콤보 박스가 동일한 문자열 값을 가질 수있는 시나리오가 있습니다. 엑사 콤보 상자가 드롭 다운에서 값을 다음 수를 위해 : "테스트"나는 작성하고 "Test1을" "Test1을" "Test1을" "Test2를", 선택된 인덱스에 기초Wpf의 ComboBox가 SelectedIndex를 실행하지 않음
다른 콤보 박스.
<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의는 "Test1을"에서 값을 변경 (같은 넣다 내가 같은 문자열 값 사이에 suffling하고 해고하지 않는다는 것입니다처럼 내 XAML은 같은데 2.
왜 SelectedItem을 사용하지 않습니까? – blindmeis
* 내가 직면 한 문제는 동일한 문자열 값 * 사이에 겪고있는 경우 SelectedIndex가 실행되지 않는다는 것입니다. 이 문장은 의미가 없습니다. 당신은 항상 다른 인덱스에 바인딩됩니다. – McGarnagle
@blindmeis : selectedindex를 기반으로 다른 콤보 상자를 채우기 때문에 선택한 색인을 사용하고 있습니다. 아무리해도 SelectedItem 또는 selectedvalue도 descibed 시나리오에서 해고되지 않습니다. –