此代碼給我一個「參數超出範圍」異常。當我刪除綁定到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