Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF TreeView not loading TreeViewItems until the parent is expanded
    text
    copied!<p>I'm experiencing an issue with a Treeview that is driving me crazy!!!</p> <p>My TreeView is databound to an object model that is 3 levels deep, and uses a HierarchicalDataTemplate to define what should be displayed for each level:</p> <p>Company<br> +-Branch<br> --+--Contact</p> <p>I want to make a specific contact the selected node, which I'm doing like this (contact is the object from the databound object model):</p> <pre><code>Dim companyTreeViewItem As TreeViewItem = Me.AgentTreeView.ItemContainerGenerator.ContainerFromItem(contact.Branch.Company) Dim branchTreeViewItem As TreeViewItem = companyTreeViewItem.ItemContainerGenerator.ContainerFromItem(contact.Branch) Dim contactTreeViewItem As TreeViewItem = branchTreeViewItem.ItemContainerGenerator.ContainerFromItem(contact) </code></pre> <p>If I expand the treeview so the node that is going to be selected is visible (and then go and select something else) this code works, however if I run it before I expand any nodes branchTreeViewItem comes back as Nothing (null).</p> <p>Any ideas how I can get to the TreeViewItem for my contact object and set it as selected?</p> <p><strong>EDIT</strong></p> <p>The code that populates the treeview is just setting the DataContext of the control:</p> <pre><code>Me.DataContext = New ObjectModel.ObservableCollection(Of DAL.Company)(From c In entities.Companies.Include("Branches").Include("Branches.Contacts") Order By c.CompanyName) </code></pre> <p>The treeview then has a simple binding</p> <pre><code>&lt;TreeView ItemsSource="{Binding}" VirtualizingStackPanel.IsVirtualizing="False" &gt; </code></pre>
 

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