Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1715
ComboEditorTool resetting value depending on data object's VALUE
posted
Ok ,this is a strange one and I have no idea why this would be occurring. I have a Ribbon with one ComboEditorTool. The tool contains objects with three properties: one int : ID, one string : Name. I bind the combo editor's ItemsProvider to an ObservableCollection of these objects. The DisplayMemberPath is set to Name and the ValuePath is set to ID.

For some objects, the ValueChanged/SelectedItemChanged events in the ComboEditorTool are raised twice! Not only that, the first event is correct specifying the old value and the new value. But the second event, actually occurs after the selected item is changed to NULL! So the eventing works fine, but for some reason the values are getting reset by the ComboEditorTool. In particular, this ONLY happens to the objects with ids between 100 and 130 (these IDs are just what my database had at the time). If I change those IDs to some single digits integers, the only object that creates this issue is the one with ID = 31.

I have attached a sample of this; I listen to the ValueChanged and SelectedItemChanged events and print out some data on each event to illustrate my point.

The fix I've found so far is to actually set the ValuePath to "Name", and only pay attention to the SelectedItemChanged event.

Has anyone seen something like this before? What kind of code could ever create behavior like this?

Thanks
Szymon
ObservableCollectionXamComboEditor.zip
  • 415
    posted

    Hi,

    Add this line of code after setting the ItemsProvider's ItemsSource property:

    comboEditor.ValueType = typeof(int);

    By default, the ComboEditorTool's ValueType property is set to typeof(string). In your application, the ComboEditorTool is trying to store the Data.ID int property as a string. This might be causing an issue where the selected value reverts back to null which in turn causes the selected value event to fire twice.