이 코드는 "범위를 벗어난 인수"예외를 제공합니다. SelectedIndex
에 대한 바인딩을 제거하면 ComboBox
이 잘 채워지고 예외가 발생하지 않습니다.WPF - ItemsSource에 바인딩하고 SelectedIndex가 예외를 throw합니까?
내가 뭘 잘못하고 있는지 알기! 이것은 (어떤 이유로) 불가능한가요?
코드 :
public class RuleMap<T> : INotifyPropertyChanged
{
public ObservableCollection<string> Options
{
get
{
return new ObservableCollection(){"A", "B", "C"};
}
}
public int SelectedIndex
{
get
{
return 0;
}
}
}
public ObservableCollection<RuleMap> FilterItemSource;
XAML :
<ItemsControl ItemsSource="{Binding FilterItemSource}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal"> <ComboBox Width="150" SelectedIndex="{Binding SelectedIndex}"
ItemsSource="{Binding Options}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
아래 답변을 참조하십시오 (2 일 동안 자신을 표시 할 수 없음). –