private TreeViewItemViewModel(BaseTreeItem treeItem, TreeViewItemViewModel parent) { _treeItem = treeItem; _parent = parent; _children = new ReadOnlyCollection <TreeViewItemViewModel>(_treeItem.Children.Select(child => new TreeViewItemViewModel(child, this)).ToList()); }
public void ReadXml(XmlReader reader) { while (reader.Read()) { reader.MoveToContent(); if (reader.LocalName.Equals("Project") && reader.NodeType == XmlNodeType.EndElement) { break; } if (reader.IsEmptyElement || reader.NodeType == XmlNodeType.EndElement) { continue; } switch (reader.LocalName) { case "Name": reader.Read(); Name = reader.Value; break; case "Path": string BasePath = reader.BaseURI.Substring(8, reader.BaseURI.Length - reader.BaseURI.Split('/').Last().Length - 9).Replace('/', '\\'); Path = Directory.Exists(reader.Value) ? reader.Value : BasePath; break; case "Children": void _readxml(BaseTreeItem rootTreeItem) { while (reader.Read()) { if (reader.LocalName.Equals("Children") && reader.NodeType == XmlNodeType.EndElement) { break; } if (reader.NodeType == XmlNodeType.Element && !reader.LocalName.Equals("Name") && !reader.LocalName.Equals("Path") && !reader.LocalName.Equals("Children")) { BaseTreeItem treeItem = (BaseTreeItem)Assembly.GetExecutingAssembly().CreateInstance("GameStoryEdit.TreeData." + reader.LocalName); while (reader.Read()) { if (reader.NodeType == XmlNodeType.EndElement && !reader.LocalName.Equals("Name") && !reader.LocalName.Equals("Path") && !reader.LocalName.Equals("Children")) { break; } if (reader.IsEmptyElement || reader.NodeType == XmlNodeType.EndElement) { continue; } switch (reader.LocalName) { case "Name": reader.Read(); treeItem.Name = reader.Value; break; case "Path": reader.Read(); treeItem.Path = Directory.Exists(reader.Value) ? reader.Value : Path.Substring(0, 3) + reader.Value.Substring(3); break; case "Children": _readxml(treeItem); break; } } if (treeItem is ScreenPlay sp && sp.Name != null && sp.Path != null) { sp.FountainEditor = new UserControls.FountainEditor(); } rootTreeItem.Children.Add(treeItem); } } } _readxml(this); break; } } }
public TreeViewItemViewModel(BaseTreeItem treeItem) : this(treeItem, null) { }