Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Treeview Bindings
    text
    copied!<p>I'm trying to bind an ObservableCollection to a treeview in WPF. It does kind-of work but not quite the way I thought it would.</p> <p><strong>This is the binding I have setup</strong> </p> <pre class="lang-xml prettyprint-override"><code> &lt;TreeView Height="250" ItemsSource="{Binding Path=TheUsers}" VerticalAlignment="Bottom" Width="500" Margin="0,39,0,0"&gt; &lt;TreeView.ItemTemplate&gt; &lt;HierarchicalDataTemplate ItemsSource="{Binding Path=Permission}"&gt; &lt;TextBlock Text="{Binding}" /&gt; &lt;/HierarchicalDataTemplate&gt; &lt;/TreeView.ItemTemplate&gt; &lt;/TreeView&gt; </code></pre> <p>This is the collection it is binding to:</p> <pre><code> ObservableCollection&lt;UserViewModel&gt; theUsers; public ObservableCollection&lt;UserViewModel&gt; TheUsers { get { return theUsers; } set { theUsers = value; OnPropertyChanged("TheUsers"); } } </code></pre> <p><strong>This is the object in the collection:</strong></p> <pre><code>public class UserViewModel { string userName = null; public string UserName { get { return userName; } set { userName = value; OnPropertyChanged("UserName"); } } int permCount = 0; public int PermCount { get { return permCount; } set { permCount = value; OnPropertyChanged("PermCount"); } } List&lt;string&gt; permission = null; public List&lt;string&gt; Permission { get { return permission; } set { permission = value; OnPropertyChanged("Permission"); } } </code></pre> <p>This is what it displays</p> <p><img src="https://i.stack.imgur.com/ujKzU.png" alt="screenshot"></p> <p>What I would like it to do is display the UserName for UserViewModel and the Permissions <code>List&lt;string&gt;</code> items as the children. What is the proper way to do this ?</p> <p>Thanks in Advance!</p>
 

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