-
Hi, I'm working on a [Expected Behavior]: When removing a selected item:
[Problem]: Everything works as expected, except when I remove an item. Sometimes, the selection briefly selects the parent before settling on the previous item: Video_2025-01-30_144213.mp4[Intended Flow]: [Actual Behavior]: [Bonus Questions]:
Thanks! [edit]: Here's my repo |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Were you meant to attach or link a project? |
Beta Was this translation helpful? Give feedback.
-
I think the problem might be in the Attached Prop with The I've tried to "hack" some stuff by adding delay and changing highlighted selected item's brush (temporarily) to transparent but I hate these approaches. Otherwise I hope the problem is not with WPF TreeView (?) |
Beta Was this translation helpful? Give feedback.
-
@miloush It works! Thank you so much for your guidance. Those "little" bug can drive crazy sometimes! I also had some help with gpt feeding it with our discussions. Video_2025-02-01_214221.mp4[Solution]: I made a custom treeview where I override public class CustomTreeView : TreeView
{
// (...)
protected override bool IsItemItsOwnContainerOverride(object item)
{
return item is CustomTreeViewItem;
}
protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Remove ||
e.Action == NotifyCollectionChangedAction.Reset)
{
// Do nothing: we are controlling selection via our view-model command.
return;
}
base.OnItemsChanged(e);
}
} And for children: public class CustomTreeViewItem : TreeViewItem
{
protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Remove ||
e.Action == NotifyCollectionChangedAction.Reset)
{
// Do nothing: bypass auto-selecting a sibling/parent.
return;
}
base.OnItemsChanged(e);
} |
Beta Was this translation helpful? Give feedback.
@miloush It works! Thank you so much for your guidance. Those "little" bug can drive crazy sometimes! I also had some help with gpt feeding it with our discussions.
Video_2025-02-01_214221.mp4
[Solution]: I made a custom treeview where I override
OnItemsChanged
: