/// <summary> /// Initializes a new instance of the RemoveLayers class. /// Takes the viewModels and sets up /// the treeview for the window. /// </summary> /// <param name="viewModels">Data for the treeview.</param> public RemoveLayers(List<RemoveLayersViewModel> viewModels) { this.InitializeComponent(); this.DataContext = viewModels; this.root = viewModels[0]; CommandBindings.Add( new CommandBinding( ApplicationCommands.Undo, (sender, e) => // Execute { e.Handled = true; root.IsChecked = false; this.tree.Focus(); }, (sender, e) => // CanExecute { e.Handled = true; e.CanExecute = root.IsChecked != false; })); this.tree.Focus(); }
/// <summary> /// Takes the collection of locations and times from the main window and converts the data /// into a list of removelayerviewmodels for the removelayers window to use. /// </summary> /// <param name="locationsTimes">Locations and times from the treeview in the mainwindow.</param> /// <returns>The data from locationsTimes in a list of removelayerviewmodels format.</returns> public static List<RemoveLayersViewModel> CreateViewModels(ObservableCollection<MenuItem> locationsTimes) { // Create the root of the tree, which is for selecting all nodes. RemoveLayersViewModel root = new RemoveLayersViewModel("All", string.Empty, string.Empty) { IsInitiallySelected = false, Children = new List<RemoveLayersViewModel>() }; // Create the rest of the treeview. Each location is a child of the // root and has the times as its children. List<RemoveLayersViewModel> locations = new List<RemoveLayersViewModel>(); foreach (MenuItem location in locationsTimes) { RemoveLayersViewModel loc = new RemoveLayersViewModel(location.Title, location.FilePath, location.TreeCanopyFilePath); List<RemoveLayersViewModel> times = new List<RemoveLayersViewModel>(); foreach (MenuItem time in location.Items) { RemoveLayersViewModel t = new RemoveLayersViewModel(time.Title, time.FilePath, location.TreeCanopyFilePath); times.Add(t); } loc.Children = times; locations.Add(loc); } root.Children = locations; root.Initialize(); return new List<RemoveLayersViewModel> { root }; }