I have a public CLR property defined in the code behind of a WPF Window. This property only has a setter defined.
public SomeCustomType SomeProperty {
set {
someValue = value;
}
}
I also have a ComboBox defined in the XAML of this WPF Window. This ComboBox has two ComboBoxItem objects defined. The Content properties of the ComboBoxItem objects are set to the text that I want to display for those items. The Tag properties of the ComboBoxItem objects are set to a static CLR property on another class. The SelectedValuePath is set to "Tag" on the ComboBox. I have the SelectedValue bound to the Window's CLR property with the mode set to OneWayToSource and the UpdateSourceTrigger set to PropertyChanged.
<ComboBox SelectedValue="{Binding Registry, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}" SelectedValuePath="Tag" SelectedIndex="0">
<ComboBoxItem Content="Item1" Tag={x:Static someNamespace:SomeType.SomeStaticCLRProperty}" />
<ComboBoxItem Content="Item1" Tag={x:Static someNamespace:SomeType.SomeStaticCLRProperty}" />
</ComboBox>
What I want to have happen is: when an item is selected in the ComboBox, the CLR property in the Window code behind should be set to the selected value. I do not want the code behind to ever set the value of the ComboBox.
But when I run this, I am getting an exception: "Property Get method was not found.". The way I read this, it is complaining that I don't have a getter defined on the Window's CLR property. But I don't think I should need one.
Am I doing something obviously wrong here?
Thanks!
EDIT: I should mention that adding the getter does make it work, but the getter is getting hit whenever the setter does. Also, the first time the setter is called (when the Window loads), the value is null. But then it doesn't get called again until the user selects something. Shouldn't I be getting a valid value from the selected value the first time around?