I am trying to produce a list of servers for browsing on a network such that it produces a tree view which looks like this:
-Local Server
- Endpoint 1
- En
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;)
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
{
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();
for (int i = 0; i < 2; i++)
{
EndPoints.Add("Endpoint"+ ++EndpointCounter);
}
}
public string Name { get; set; }
public ObservableCollection EndPoints { get; set; }
}
}