Binding in XAML to SelectedItem or SelectedValue or SelectedIndex of a Combobox throws XamlDuplicateMemberException.
Repro steps
Create XAML with a ComboBox in which ItemSource and SelectedItem are bound to some model properties. E.g.
<ComboBox ItemsSource="{Binding AllItems}" SelectedItem="{Binding CurrentItem}" / >
ViewModel has properties defined as:
let items = [|"One"; "Two"|]
member this.AllItems with get() = items
member this.CurrentItem with get() = items.[1]
Expected behavior
No exceptions thrown. The combobox has two items with second item selected.
Actual behavior
Exception on creating instance of the view type defined as XAML<"View.xaml">:
System.Xaml.XamlDuplicateMemberException was unhandled
Message: An unhandled exception of type 'System.Xaml.XamlDuplicateMemberException' occurred in System.Xaml.dll
Additional information: 'SelectedItem' property has already been set on 'ComboBox'.
Known workarounds
Setting selected item using code-behind works as expected.
Description
Binding in XAML to SelectedItem or SelectedValue or SelectedIndex of a Combobox throws XamlDuplicateMemberException.
Repro steps
Create XAML with a ComboBox in which ItemSource and SelectedItem are bound to some model properties. E.g.
<ComboBox ItemsSource="{Binding AllItems}" SelectedItem="{Binding CurrentItem}" / >
ViewModel has properties defined as:
Expected behavior
No exceptions thrown. The combobox has two items with second item selected.
Actual behavior
Exception on creating instance of the view type defined as XAML<"View.xaml">: System.Xaml.XamlDuplicateMemberException was unhandled Message: An unhandled exception of type 'System.Xaml.XamlDuplicateMemberException' occurred in System.Xaml.dll Additional information: 'SelectedItem' property has already been set on 'ComboBox'.
Known workarounds
Setting selected item using code-behind works as expected.
Related information