我有一個組合框可以有相同的字符串值的場景。對於EXA組合框可以有以下的下拉值: 「測試」, 「測試1」, 「測試1」, 「測試1」, 「的Test2」,Wpf的ComboBox沒有觸發SelectedIndex
在選擇指數的基礎上,我填另一個組合框。我的XAML的樣子:
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="40"></RowDefinition>
</Grid.RowDefinitions>
<ComboBox ItemsSource="{Binding Path=ComboList, Mode=OneWay}"
SelectedIndex="{Binding Path=ComboIndex, Mode=TwoWay}"/ >
</Grid>
視圖模型的樣子:
class TestViewModel : INotifyPropertyChanged
{
private IList<string> _comboList = new List<string>
{
"Test",
"Test1",
"Test1",
"Test1",
"Test2",
};
public IList<string> ComboList
{
get { return _comboList; }
}
private int _comboIndex;
public int ComboIndex
{
get { return _comboIndex; }
set
{
if (value == _comboIndex)
{
return;
}
_comboIndex = value;
OnPropertyChanged("ComboIndex");
}
}
private void OnPropertyChanged(string prop)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(prop));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
問題,我面對的是,SelectedIndex的不解僱櫃面我相同的字符串值之間suffling(像「Test1的」改變價值,本索引1處,以「測試1」,存在於2
爲什麼不使用SelectedItem? – blindmeis
*我面對的問題是SelectedIndex不會被解僱,因爲我在同一個字符串值*之間成功。這種說法沒有道理。你綁定到索引,這將永遠是不同的。 – McGarnagle
@blindmeis:我正在使用選定的索引,因爲根據selectedindex我需要填充另一個組合框。無論如何,即使SelectedItem或selectedvalue也不會在descibed場景中被解僱。 –