Hello!
I have a trouble with selecting initial items of XamComboEditor. The examples are attached.
When I populate SelectedItems from my ViewModel, the binding is OK, because the binded list displays my collection. But the XamComboEditor is empty, no checkboxes are set, although it does not display the EmptyText.
When I select some other item inside the XamComboEditor, it is added to the list, the initial item appears inside the XamComboEditor's text field (but the corresponding checkbox is still unset). When I deselect it, it is removed from the list, and only the initial value remains in the text field.
But when I select initial item, it is not added to the list (looks like it just hooks up to the existing one). And when I deselect it, it is removed from the list, and the the provided EmptyText is displayed.
Can you please look at my code?
Hello Pavel,
Thank you for your response. I am glad I was able to assist you on this issue.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Thank you, Andrew! I changed the setter as you said and also overriden the == and != operators, and it became possible to not set SelectedRegions from Regions elements, but to construct it separately, as was implemented before.
Thank you for your post.
I have been investigating into the sample code files that you have sent, and there are a couple of issues that are preventing the XamComboEditor from working correctly in this case.
The first issue exists in both of the projects that are attached in the implementation of the setters of the SelectedRegions collection. Currently, the if-statement in your setter reads:
if (_selectedRegions == null) _selectedRegions = value;
This will only be hit the first time, but when the XamComboEditor loads, it will make a second call to this setter for the committing of the SelectedItems collection to the editor. The above will prevent this change from happening, as your _selectedRegions collection will no longer be null, and so you will get some strange behavior with the XamComboEditor's selected items collection.
The second issue exists only in the "ExampleWithObjects" project. The SelectedRegions collection in this project is currently being populated with a "same-but-different" IdentifierDetail object. Being that this is a complex object, and even though it does have the same property values, it is not the same instance of an object that exists in the ItemsSource of the XamComboEditor. The instances of these items needs to remain consistent, as the XamComboEditor will not know what to do with the new instance of your object. If you change the SelectedRegions initialization to something like the following (after changing the setter):
SelectedRegions = new ObservableCollection<object>() { Regions[1] };
You should see that the selected items will be populated in the XamComboEditor on load.
I have attached a modified version of the sample project(s) you sent to demonstrate the above. I hope this helps you.