Note that there are some explanatory texts on larger screens.

plurals
  1. POTreeView Sometimes Not Updated
    primarykey
    data
    text
    <p>I have a TreeView that is bound to an ObservableCollection in my ViewModel. I have an issue where if I add an item to the ObservableCollection, sometimes it isn't displayed in the GUI. </p> <p>I have debugged and found that the item indeed gets added and the CollectionChanged event does indeed get fired on the observable collection. Other parts of my GUI even update to reflect the newly added and selected item. The only problem is that the new item does not show up in the TreeView. </p> <p>It's a bit strange because sometimes it will show up, sometimes it will flicker up then go away, and sometimes it won't show up at all. Any ideas?</p> <p>EDIT:</p> <p>TreeView XAML:</p> <pre><code> &lt;TreeView Name="cedarTreeView" ItemsSource="{Binding CurrentFiles}" ItemTemplate="{StaticResource MyFileTemplate}" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"&gt; &lt;TreeView.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;VirtualizingStackPanel /&gt; &lt;/ItemsPanelTemplate&gt; &lt;/TreeView.ItemsPanel&gt; &lt;TreeView.ItemContainerStyle&gt; &lt;Style TargetType="TreeViewItem"&gt; &lt;Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" /&gt; &lt;Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" /&gt; &lt;Setter Property="FontSize" Value="12" /&gt; &lt;Setter Property="AllowDrop" Value="True" /&gt; &lt;/Style&gt; &lt;/TreeView.ItemContainerStyle&gt; &lt;/TreeView&gt; </code></pre> <p>The DataTemplate:</p> <pre><code>&lt;HierarchicalDataTemplate x:Key="MyFileTemplate" ItemTemplate="{StaticResource QualifierTemplate}" ItemsSource="{Binding Qualifiers, Converter={StaticResource SortByNameConverter}}"&gt; &lt;HierarchicalDataTemplate.ItemContainerStyle&gt; &lt;Style TargetType="{x:Type TreeViewItem}"&gt; &lt;Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" /&gt; &lt;Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" /&gt; &lt;Setter Property="Visibility" Value="{Binding IsVisible, Converter={StaticResource BoolToVisConverter}}" /&gt; &lt;/Style&gt; &lt;/HierarchicalDataTemplate.ItemContainerStyle&gt; &lt;TextBlock Text="{Binding Name, Mode=OneWay}" ToolTip="{Binding Name, Mode=OneWay}" Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=TreeView}}"&gt; &lt;TextBlock.ContextMenu&gt; Some Context Menu Stuff Here &lt;/TextBlock.ContextMenu&gt; &lt;/TextBlock&gt; &lt;/HierarchicalDataTemplate&gt; </code></pre> <p>I am adding to the Qualifiers ObservableCollection. It displays them fine when I first open the file and add all of the existing ones. The problem is when i try to create a new one.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload