此代码给我一个“参数超出范围”异常。当我删除绑定到SelectedIndex
时,ComboBox
填充得很好,并且不会引发异常。WPF - 绑定到一个ItemsSource和SelectedIndex引发异常?
任何想法我做错了什么?这(出于某种原因)不可能吗?
代码:
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天)。 – 2009-12-03 23:02:58