c# - 组合框列表更改时属性值更改为空(WPF)
问题描述
我根据条件将两个不同的列表绑定到单个组合框。
我的第一个列表包含 1,2,3,4,5,6,我的第二个列表包含 2,5,6,我根据条件从后面的代码中通过 Itemsource 将这些列表添加到组合框。
我有行网格(AllUsers 和 SomeUsers 相关数据),当我单击 AllUsers 数据行然后在网格行选择更改时,我将第一个列表从后面的代码绑定到组合框。当我单击 SomeUsers 数据行然后在网格行选择更改时,我将第二个列表从后面的代码添加到组合框。
在这里,我对网格数据和组合框使用了 observable 集合(它是 observable 集合的子列表)。在组合框中选择的任何数据都会自动更新到我的网格模型(我在组合框中使用两种方式绑定)。
Problem :- when selection changed happens I was adding relevant list to combobox through Item source from code behind , at that time previously selected value is getting null in the model property(especailly 1st list items when property contains 1 or 3 or 4 values) because那些在第二个组合框列表中不存在。
注意:- 组合框在网格之外。
架构:-不是 MVVM
<ComboBox Name="cbNum" Margin="3" Background="White" SelectedValue="{Binding UserGroup, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="28" FontSize="13" Grid.Column="1" DisplayMemberPath="Meaning" SelectedValuePath="LookupCode" VerticalContentAlignment="Center" BorderBrush="#b3b3b3"></ComboBox>
if (strCondition == "1stList")
cbNum.ItemsSource = lstFirtstList;
if (strCondition == "2ndList")
cbNum.ItemsSource = lstsecondList;
解决方案
推荐阅读
- cassandra - Cassandra Datastax Java 驱动程序看不到配置中的环境变量
- python - 将数据框列拆分为多列
- python - 如何使我的 pygame 窗口最小化和最大化?
- c# - 如何通过 C# 中的 Graph API 更新用户的邮箱时区
- python - Python中for和while循环的性能差异
- python - 函数 tensor.cpu() 使用 pytorch xla 多核需要很多时间
- python - 如何最好地在 celery 中设置异构工作负载?
- ajax - 将处理的 ajax 数据传递给路由 Laravel 6.x
- sql-server - API 中调用函数检索加载资源失败:服务器响应状态为 500 ()
- python - 适用于 Python 的 Google Sheets API:复制工作表时出现空图表