ItemsSourceプロパティがObservableCollectionプロパティにバインドされ、SelectedIndexプロパティが整数プロパティにそれぞれバインドされているコンボボックスがあります。
<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」プロパティの変更イベントを呼び出すため)、アプリケーションがクラッシュします。
なぜこれが起こっているのかわかりません。誰かが光を当てて解決策を提案できますか?
TIA...スディープ