gpt4 book ai didi

silverlight - 为什么实现 ObservableCollection 会使我的 silverlight 应用程序崩溃?

转载 作者:行者123 更新时间:2023-12-03 17:43:53 26 4
gpt4 key购买 nike

我有一个组合框,其 ItemsSource 属性绑定(bind)到 ObservableCollection 属性,其 SelectedIndex 属性分别绑定(bind)到整数属性。

<ComboBox Name="cmbDealt" ItemsSource="{Binding Path=DealList, Mode=TwoWay}" SelectedIndex="{Binding Mode=TwoWay, Path=DealIndex}"></ComboBox>
<CheckBox IsChecked="{Binding Mode=TwoWay, Path=SomeCondition}" Content="Some Condition"></CheckBox>

我的数据结构看起来像
 private ObservableCollection<string> m_DealList = null;
private int m_DealIndex = 0;
private bool m_SomeCondition = false;

public ObservableCollection<string> DealList
{
get
{
if (m_DealList == null)
m_DealList = new ObservableCollection<string>();
else
m_DealList.Clear();

if (m_SomeCondition)
{
m_DealList.Add("ABC");
m_DealList.Add("DEF");
}
else
{
m_DealList.Add("UVW");
m_DealList.Add("XYZ");
}
return m_DealList;
}
}

public int DealIndex
{
get { return m_DealIndex; }
set
{
if (value != -1)
{
m_DealIndex = value;
}
}
}

public bool SomeCondition
{
get { return m_SomeCondition; }
set
{
m_SomeCondition = value;
OnPropertyChanged("DealList");
OnPropertyChanged("DealIndex");
}
}

现在应用程序加载成功。但是,当用户将 ComboBox 的 SelectedIndex 从 0 更改为 1,然后选中复选框(以调用“DealIndex”属性更改事件)时,应用程序崩溃。

我不确定为什么会发生这种情况。有人可以阐明并提出解决方案吗?

蒂亚...
苏迪普

最佳答案

一种选择是将绑定(bind)从 selectedindex 更改为 selecteditem。你可以完成同样的事情。我最初是从尝试更改 selectedindex 开始的,但从未成功。我认为它可能是只读的。

关于silverlight - 为什么实现 ObservableCollection 会使我的 silverlight 应用程序崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/992848/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com