private void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { this.Loaded -= OnLoaded; Task.Factory.StartNew(() => { var list = new DeckList(Paths.Get().DeckPath, this.Dispatcher, null, true) { Name = "All" }; Dispatcher.Invoke(new Action(() => DeckLists.Add(list))); Dispatcher.Invoke(new Action(() => { SelectedList = null; SelectedList = list; foreach (DeckList item in FolderTreeView.Items) { if (item.Name != "All") { continue; } TreeViewItem tvi = FolderTreeView.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem; if (tvi != null) { Task.Factory.StartNew(() => { Thread.Sleep(10); Dispatcher.Invoke(new Action( () => { try { tvi.IsSelected = true; } catch { } })); }); break; } } })); IsLoading = false; }); }
private void SortDeckLists() { string currentFilePath = SelectedDeckList.FilePath; List <DeckList> sorted = DeckLists.OrderBy(l => l.Name).ToList(); DeckLists.Clear(); DeckListIndex = 0; for (int i = 0; i < sorted.Count(); i++) { DeckLists.Add(sorted[i]); if (sorted[i].FilePath.Equals(currentFilePath)) { DeckListIndex = i; } } OnPropertyChanged("DeckLists"); OnPropertyChanged("DeckListIndex"); }