public TreeItem Clone() { TreeItem clone = new TreeItem(this.Name, this.Item); foreach (var ti in this.Children) { clone.AddChild(ti.Clone()); } return(clone); }
// Helper for building a tree describing the profiles private void ProfileTreeHelper(IEnumerable <Profile> profiles, TreeItem parent) { foreach (Profile p in profiles) { var ti = new TreeItem(p.Name, p); // Hook on a handler to deal with name changes ti.NameChanged += new NameChangedEventHandler(treeItem_NameChanged); // Selection is controlled programmatically through binding to IsSelected if (p == SelectedProfile) { ti.IsSelected = true; } parent.AddChild(ti); } }
public void PopulateSystemProperties() { IPropertyDescriptionList propertyDescriptionList = null; IPropertyDescription propertyDescription = null; Guid guid = new Guid(ShellIIDGuid.IPropertyDescriptionList); try { int hr = PropertySystemNativeMethods.PSEnumeratePropertyDescriptions(PropertySystemNativeMethods.PropDescEnumFilter.PDEF_ALL, ref guid, out propertyDescriptionList); if (hr >= 0) { uint count; propertyDescriptionList.GetCount(out count); guid = new Guid(ShellIIDGuid.IPropertyDescription); Dictionary <string, List <string> > dict = new Dictionary <string, List <string> >(); for (uint i = 0; i < count; i++) { propertyDescriptionList.GetAt(i, ref guid, out propertyDescription); string propName; propertyDescription.GetCanonicalName(out propName); List <string> names = null; string[] parts = propName.Split('.'); if (parts.Count() == 2) { // System.Foo if (!dict.TryGetValue(parts[0], out names)) { names = new List <string>(); dict.Add(parts[0], names); } names.Add(parts[1]); } else if (parts.Count() == 3) { // System.Bar.Baz if (!dict.TryGetValue(parts[1], out names)) { names = new List <string>(); dict.Add(parts[1], names); } names.Add(parts[2]); } // If we ever need it: // ShellPropertyDescription desc = new ShellPropertyDescription(propertyDescription); if (propertyDescription != null) { Marshal.ReleaseComObject(propertyDescription); propertyDescription = null; } } // build tree foreach (string cat in dict.Keys) { TreeItem main = new TreeItem(cat, PropType.Group); foreach (string name in dict[cat]) { main.AddChild(new TreeItem(name, PropType.Normal)); } if (cat == "System") { AllProperties.Insert(0, main); } else if (cat == "PropGroup") { foreach (TreeItem ti in main.Children) { GroupProperties.Add(ti.Name); } } else { AllProperties.Add(main); } } } } finally { if (propertyDescriptionList != null) { Marshal.ReleaseComObject(propertyDescriptionList); } if (propertyDescription != null) { Marshal.ReleaseComObject(propertyDescription); } } }