Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, this is the closest I can come to your requirements. All the functionality is not contained within one TreeView, nor is it bound to a compositecollection, but that can remain a secret between you and me;)</p> <pre><code>&lt;Window x:Class="CompositeCollectionSpike.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300" xmlns:local="clr-namespace:CompositeCollectionSpike"&gt; &lt;StackPanel&gt; &lt;StackPanel.Resources&gt; &lt;Style TargetType="TreeView"&gt; &lt;Setter Property="BorderThickness" Value="0"/&gt; &lt;/Style&gt; &lt;HierarchicalDataTemplate DataType="{x:Type local:Server}" ItemsSource="{Binding EndPoints}"&gt; &lt;Label Content="{Binding Name}"/&gt; &lt;/HierarchicalDataTemplate&gt; &lt;/StackPanel.Resources&gt; &lt;TreeView ItemsSource="{Binding LocalServer}"/&gt; &lt;TreeViewItem DataContext="{Binding RemoteServers}" Header="{Binding Description}"&gt; &lt;StackPanel&gt; &lt;Button Click="Button_Click"&gt;Add Remote Server&lt;/Button&gt; &lt;TreeView ItemsSource="{Binding}"/&gt; &lt;/StackPanel&gt; &lt;/TreeViewItem&gt; &lt;/StackPanel&gt; </code></pre> <p></p> <pre><code>using System.Collections.ObjectModel; using System.Windows; namespace CompositeCollectionSpike { public partial class Window1 : Window { private ViewModel viewModel; public Window1() { InitializeComponent(); viewModel = new ViewModel { LocalServer =new ServerCollection{new Server()}, RemoteServers = new ServerCollection("Remote Servers") {new Server(), new Server(), new Server()}, }; DataContext = viewModel; } private void Button_Click(object sender, RoutedEventArgs e) { viewModel.LaunchAddRemoteServerDialog(); } } public class ViewModel:DependencyObject { public ServerCollection LocalServer { get; set; } public ServerCollection RemoteServers { get; set; } public void LaunchAddRemoteServerDialog() {} } public class ServerCollection:ObservableCollection&lt;Server&gt; { public ServerCollection(){} public ServerCollection(string description) { Description = description; } public string Description { get; set; } } public class Server { public static int EndpointCounter; public static int ServerCounter; public Server() { Name = "Server"+ ++ServerCounter; EndPoints=new ObservableCollection&lt;string&gt;(); for (int i = 0; i &lt; 2; i++) { EndPoints.Add("Endpoint"+ ++EndpointCounter); } } public string Name { get; set; } public ObservableCollection&lt;string&gt; EndPoints { get; set; } } } </code></pre>
    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.
    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