Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom WPF TreeView
    primarykey
    data
    text
    <p>I have a custom class that I would like to bind a WPF TreeView that has three tiers. Each tier needs to be bound like this:</p> <pre><code> Monitor --&gt; LCD --&gt; Samsung 1445 LCD --&gt; CRT --&gt; Sony 125 CRT </code></pre> <p>Here is the example code:</p> <pre><code>public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); SystemInventory sysInventory = new SystemInventory(); //Possibly do something like this. _myTreeView.DataContext = sysInventory.DeviceGroupInstances; } public class SystemInventory { public ObservableCollection&lt;DeviceGroup&gt; DeviceGroupInstances { get; set; } public SystemInventory() { DeviceGroupInstances = new ObservableCollection&lt;DeviceGroup&gt;(); DeviceGroupInstances.Add(new DeviceGroup("Monitor")); } } public class DeviceGroup { public string DeviceGroupName { get; set; } public ObservableCollection&lt;DeviceType&gt; DeviceTypeInstances { get; set; } public DeviceGroup(string deviceGroupName) { DeviceTypeInstances = new ObservableCollection&lt;DeviceType&gt;(); DeviceGroupName = deviceGroupName; if (deviceGroupName == "Monitor") { DeviceTypeInstances.Add(new DeviceType("LCD")); DeviceTypeInstances.Add(new DeviceType("CRT")); } } } public class DeviceType { public string DeviceTypeName { get; set; } public ObservableCollection&lt;DeviceInstance&gt; DeviceInstances { get; set; } public DeviceType(string deviceGroupName) { DeviceInstances = new ObservableCollection&lt;DeviceInstance&gt;(); DeviceTypeName = deviceGroupName; if (deviceGroupName == "Monitor") { DeviceInstances.Add(new DeviceInstance("Samsung 1445 LCD")); } else { DeviceInstances.Add(new DeviceInstance("Sony 125 CRT")); } } } public class DeviceInstance { public string DeviceInstanceName { get; set; } public DeviceInstance(string instanceName) { DeviceInstanceName = instanceName; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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