Monday 15 March 2010

wpf - Detecting initialisation change vs. user change in ComboBox -


It looks like one of those questions that should be really clear, but I do not get the answer right now.

I have some XML which is similar to the following:

  & lt; Checkbox isChecked = "{Binding ShouldCopySettings}" /> & Lt; Combobox selected item = "{binding copy settings}" itemsource = "{binding source = {static resource group}" & gt; & Lt; ComboBox.GroupStyle & gt; & Lt; Static resource resource = "item group style" /> & Lt; /ComboBox.GroupStyle> & Lt; / ComboBox & gt;   

ItemSource is a CollectionViewSource which uses GroupDescriptions ; I'm not sure whether this is a factor or not.

Everything behaves in relation to the built-in ViewModel object with the basic implementation ShouldCopySettings The initial state of the property is incorrect and the CopySettingsFrom the initial position of the property is zero is. An unpredictable (but tolerable) behavior is that the combobox appears to auto-select the first item in the list, when the original datacontest is assigned, and CopySettingsFrom Puts on.

But now I want to auto-tick this checkbox if my user selects from the cumbobox, my first inclination, it should be from ShouldCopySettings to CopySettingsFrom property To provide real property from Setter - and it really works.

However, on the issue of the initialization described above, when the datacontext was initially assigned (which is outside the control of this view-modal), this will always keep the checkbox and ShouldCopySettings To correct, the data will result in regardless of its initial state, which is clearly unacceptable.

So I have to find out that this is starting the combo, so that I would like to avoid changing the checkbox property, or I can better see it for linking.

I am posting it as an answer to my own question because it works, But I'm not particularly happy with it and I welcome the better option.

What I have done for this moment CopySettingsFrom setter so that it should only set the property to ShouldCopySettings if its old value of its property is a non -Example Value.

This ignores the initial combobox int because it is a change from the blank to the non-null as the reason for the change of the user action is not possible, so it should never be repeated again.

No comments:

Post a Comment