public void LoadXml() { Categories = new List <SwfCategory>(); XElement xele = XElement.Load("SwfList.xml"); var files = xele.DescendantsAndSelf("File").ToList(); foreach (var xElement in files) { var file = new SwfItem { FilePath = Path.Combine(Directory.GetCurrentDirectory(), "Movies", xElement.Attribute("Path").Value), Title = xElement.Attribute("Title").Value }; var categoryName = xElement.Attribute("Category").Value; var category = Categories.FirstOrDefault(c => c.Name == categoryName); if (category == null) { category = new SwfCategory { Name = categoryName, IsExpanded = true }; Categories.Add(category); category.PropertyChanged += (s, a) => { if (a.PropertyName != SwfCategory.SelItemPropertyName) { return; } this.SelectedFile = ((SwfCategory)s).SelItem; }; } category.AddItem(file); } }
internal void AddItem(SwfItem file) { if (this.Items == null) { this.Items = new ObservableCollection <SwfItem>(); } this.Items.Add(file); file.Category = this; }