Avoid the collapsing effect on TreeView after updating data
- by Manolete
I have a TreeView used to display events. It works great, however every time new events are coming in and populating the tree collapse the tree again to the original position. That is very annoying when the refresh time is less than 1 second and it does not allow the user to interact with the items of the tree.
Is there any way to avoid this behaviour?
<TreeView Margin="1" BorderThickness="0" Name="eventsTree" ItemsSource="{Binding EventAlertContainers}"
Background="#00000000" ScrollViewer.VerticalScrollBarVisibility="Auto" FontSize="14"
VirtualizingStackPanel.IsVirtualizing="True">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type C:EventAlertContainer}" ItemsSource="{Binding EventAlerts}">
<StackPanel Orientation="Horizontal">
<Image Width="20" Height="20" Margin="3,0" Source="Resources\Process_info_32.png" />
<TextBlock FontWeight="Bold" FontSize="16" Text="{Binding Description}" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type C:EventAlert}" ItemsSource="{Binding Events}">
<StackPanel Orientation="Horizontal">
<Image Width="20" Height="20" Margin="0,0" Source="Resources\clock2_32.jpg" />
<TextBlock FontWeight="DemiBold" FontSize="14" Text="{Binding Name}" />
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type C:Event}">
<StackPanel Orientation="Horizontal">
<Image Width="20" Height="20" Margin="0,0" Source="Resources\Task_32.png" />
<StackPanel Orientation="Vertical">
<TextBlock FontSize="12" Text="{Binding Name}" />
</StackPanel>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>