WPF TreeView focusing on newly added item
I have a sorted tree with a lot of items. When I add a new item, I would like the new item to be selected and displayed on the screen. For example: if I see the first 10 items on the screen, and a new item is added at the 20th position, then the view should change to represent the newly added item (it can be first on screen, last or in the middle - it doesn't matter). I can get the selection working after reading some blog posts. Please help me learn how to achieve the desired display functionality.
Lukash Glaz
+2
source to share
2 answers
I suggest you take a look at this article where the author shows you how to use the attached behavior. With this behavior, you can do everything in XAML:
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter
Property="local:TreeViewItemBehavior.IsBroughtIntoViewWhenSelected"
Value="True"
/>
</Setter>
</Style>
</TreeView.ItemContainerStyle>
Where IsBroughtIntoViewWhenSelected is the attached property.
+4
source to share