private void TvTree_OnDrop(object sender, DragEventArgs e) { TreeViewItem dropTarget = (TreeViewItem)sender; if (dropTarget == null || !this.dragging) { return; } // Check if any data is present. if (!e.Data.GetDataPresent(DataFormats.StringFormat)) { return; } string dragSourceBlueprintId = (string)e.Data.GetData(DataFormats.StringFormat); BlueprintViewModel dropTargetBlueprint = (BlueprintViewModel)dropTarget.Header; // Prevent dragging and dropping on self. if (dragSourceBlueprintId.Equals(dropTargetBlueprint.BlueprintId)) { return; } // Reparent blueprint. BlueprintManagerViewModel viewModel = this.DataContext as BlueprintManagerViewModel; if (viewModel != null) { viewModel.ReparentBlueprint(dragSourceBlueprintId, dropTargetBlueprint.BlueprintId); } // Stop dragging to prevent raising the drop event on parent items. this.dragging = false; }
public void SetUp() { this.testBlueprintManager = new HierarchicalBlueprintManager(); this.testBlueprintManager.AddChild(new BlueprintManager()); this.testViewModel = new BlueprintManagerViewModel(new List<Type>(), this.testBlueprintManager); this.testViewModel.CurrentBlueprintManager = (BlueprintManager)this.testBlueprintManager.Children.First(); UndoService.Current.Clear(); }
public void SetUp() { this.testBlueprintManager = new HierarchicalBlueprintManager(); this.testBlueprintManager.AddChild(new BlueprintManager()); this.testViewModel = new BlueprintManagerViewModel(new List <Type>(), this.testBlueprintManager); this.testViewModel.CurrentBlueprintManager = (BlueprintManager)this.testBlueprintManager.Children.First(); UndoService.Current.Clear(); }
private void UpdateSelectedBlueprint() { // Search for view model in current blueprints. BlueprintManagerViewModel dataContext = (BlueprintManagerViewModel)this.DataContext; var selectedBlueprint = dataContext != null ? dataContext.Blueprints.FirstOrDefault( blueprint => blueprint.BlueprintId == this.selectedBlueprintId) : null; this.ComboBox.SelectedItem = selectedBlueprint; }
private void ExecutedCreateNewBlueprint(object sender, ExecutedRoutedEventArgs e) { try { BlueprintManagerViewModel viewModel = this.DataContext as BlueprintManagerViewModel; if (viewModel != null) { viewModel.CreateNewBlueprint(); } } catch (ArgumentException ex) { EditorDialog.Error("Unable to add blueprint", ex.Message); } }
private ListCollectionView CreateBlueprintsView() { BlueprintManagerViewModel dataContext = (BlueprintManagerViewModel)this.DataContext; if (dataContext == null) { return(null); } ListCollectionView newBlueprintsView = new ListCollectionView(dataContext.Blueprints); newBlueprintsView.SortDescriptions.Add(new SortDescription("BlueprintId", ListSortDirection.Ascending)); if (this.Filter != null) { newBlueprintsView.Filter = blueprint => this.Filter((BlueprintViewModel)blueprint); } return(newBlueprintsView); }
private void CanExecuteCreateNewBlueprint(object sender, CanExecuteRoutedEventArgs e) { BlueprintManagerViewModel viewModel = this.DataContext as BlueprintManagerViewModel; e.CanExecute = viewModel == null || viewModel.CanExecuteCreateNewBlueprint(); }