This project is read-only.


IsSelected == true with binding


I am trying to bind the TreeViewItemEx's IsSelected property with my model and I am facing an issue.

I have a strange behaviour when I set the model's IsSelected property before the TreeView is created : The item is visually selected, but when you click on another item, it does not behave as a selected item.

After digging a little, I found that the selected items list is empty when you first click on an item. I think it should be initialized at tree view creation.

Please find attached a sample code.

file attachments

Closed Aug 3, 2014 at 4:28 PM by slompf
Never mind, I could open the project.

So what you try is to add an item to selection on start. You could do it by calling
of better by binding some observablecollection from the viewmodel.

Setting the IsSelected propery will not work because the selection mechanism does not realize that. See IsSelected more as an internal property.


slompf wrote Aug 3, 2014 at 3:56 PM

Im not sure, what you want to say. The selecteditems list is initialized in constructor. There are not many options to do it more early.

I cannot open your project. Can you please check, if it is valid?

wrote Aug 3, 2014 at 4:28 PM

wrote Aug 3, 2014 at 4:28 PM

wrote Aug 4, 2014 at 10:07 AM

cube45 wrote Aug 4, 2014 at 10:07 AM

I solved my problem by modifying the VirtualizingTreePanel's MeasureOverride method.

There are two case :
If the TreePanel is virtualizing, this kind of selection causes a problem: Some selected items may be hidden. I don't know what the "right" behaviour should be in this case, but I added a throw...
Otherwise, check every item's IsSelected property and add it to the SelectedItems list accordingly.

Please find attached a patch of what I am doing.

Do you think there can be some issues by doing so?

wrote Aug 4, 2014 at 12:38 PM

cube45 wrote Aug 4, 2014 at 12:38 PM

One more issue related to this :
When you select an item in the tree view, unload the treeView (for example by switching tabs), deselect the item by code and get back on the treeview, the deselected item does not disappear from the SelectedItems list.
Here is another fix for that (the "f34..." patch file)