Skip to content

Add bindable DP TreeListView.SelectedItems #3849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

corvinsz
Copy link
Member

This adds a DP called SelectedItems to the TreeListView control.
There was a small hurdle to overcome, because of the TreeListViews impl., which adds (when expanding) and deletes (when collapsing) childs.
Bascially internally there are now 2 SelectedItems Lists:

  1. The base.SelectedItems (inherited from ListView) which only contains the visually selected items
  2. The SelectedItems (Dependency property) which always contains all of the selected items. This is the one the consumers see/use.

I also added tests for this new DP and showcases to the MD2&3 demos.

treeListViewSelectedItems

Comment on lines +1059 to +1066
if (dataContext is TreeListViewDataBinding viewModelA)
{
Assert.Equal(2, viewModelA.SelectedItems.Count);
}
if (dataContext is TreeListViewImplicitTemplate viewModelB)
{
Assert.Equal(2, viewModelB.SelectedItems.Count);
}
Copy link
Member Author

@corvinsz corvinsz May 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test tests 2 different UserControls with 2 different ViewModels. I somehow have to access the ViewModels. I know putting if-conditions in tests is not a good idea, but I opted to go this way.
Alternatively I could have created an interface to expose the SelectedItems property, but I think adding an interface just for the purpose of this test is a bit too much.
Other opinions/thoughts are welcome.

Fixing minor code issue
Copy link
Member

@Keboo Keboo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is starting to look good. I pushed up a few minor changes and some failing tests that we probably want to address.

@corvinsz
Copy link
Member Author

corvinsz commented Jun 5, 2025

The only thing left to solve is dealing with the correct selection of duplicate items. At least this is the last and only failing test (TreeListView_AddingDuplicateItemsAndSelectingWithArrowKeys_SelectsEachItemInTurn) you have added.

So far I was unable to find a solution for this. Keeping track of the selected items via reference (that's how it currently works) clearly doesn't work with duplicate items.

I was trying to make it work by keeping track of the selected item(s) via their index. This however also doesn't work since the TreeListView removes child nodes when collapsing a parent node. Maybe some kind of an internal data structure is the solution here?
Help and opinions on this are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants