private void CopyItem(Model.KeyGroup _sourceItem, Model.KeyGroup _targetItem) { if (_sourceItem.Gruppenname == "Root") { return; } //Asking user wether he want to drop the dragged TreeViewItem here or not if (MessageBox.Show("Wollen sie die Gruppe " + _sourceItem.Gruppenname + " in die Gruppe " + _targetItem.Gruppenname + " verschieben?", "Bearbeitung Gruppen", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { try { _targetItem.KeyGroups.Add(_sourceItem); if (RootTreeViewItem != null) { Model.KeyGroup tmp = RootTreeViewItem.DataContext as Model.KeyGroup; tmp.KeyGroups.Remove(_sourceItem); } else { } } catch (Exception ex) { System.Diagnostics.Debug.Print("CopyItem:" + ex.Message.ToString()); } } }
private void ExtendedTreeView_DragOver(object sender, DragEventArgs e) { try { Point currentPosition = e.GetPosition(this); if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > 10.0) || (Math.Abs(currentPosition.Y - _lastMouseDown.Y) > 10.0)) { // Verify that this is a valid drop and then store the drop target Model.KeyGroup item = GetNearestContainer(e.OriginalSource as UIElement); if (item != null) { if (CheckDropTarget(draggedItem, item)) { e.Effects = DragDropEffects.Move; } else { e.Effects = DragDropEffects.None; } } } e.Handled = true; } catch (Exception ex) { System.Diagnostics.Debug.Print("DragOver:" + ex.Message.ToString()); } }
private void ExtendedTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { Model.KeyGroup kg = (Model.KeyGroup)e.NewValue; TreeViewItem tvi = GetItemFromObject(kg); RootTreeViewItem = GetRootItem(tvi); if (RootTreeViewItem != null) { System.Diagnostics.Debug.Print(RootTreeViewItem.Header.ToString()); } }
private bool CheckDropTarget(Model.KeyGroup _sourceItem, Model.KeyGroup _targetItem) { //Check whether the target item is meeting your condition bool _isEqual = false; if (_sourceItem.Gruppenname != _targetItem.Gruppenname) { _isEqual = true; } return(_isEqual); }
private Model.KeyGroup GetNearestContainer(UIElement element) { // Walk up the element tree to the nearest tree view item. TreeViewItem UIContainer = FindParent <TreeViewItem>(element); Model.KeyGroup NVContainer = null; if (UIContainer != null) { NVContainer = UIContainer.DataContext as Model.KeyGroup; } return(NVContainer); }
private void cboGroups_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count > 0) { Model.KeyGroup skg = (Model.KeyGroup)e.AddedItems[0]; if (skg != vmMain.SelectedGroup) { if (vmMain.SelectedGroup.KeyEntries.Contains(vm.SelectedKey)) { skg.KeyEntries.Add(vm.SelectedKey); vmMain.SelectedGroup.KeyEntries.Remove(vm.SelectedKey); vmMain.SelectedGroup = skg; } } } }
private void ExtendedTreeView_MouseMove(object sender, MouseEventArgs e) { try { if (e.LeftButton == MouseButtonState.Pressed) { UIElement element = e.OriginalSource as UIElement; Point currentPosition = e.GetPosition(this); if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > 10.0) || (Math.Abs(currentPosition.Y - _lastMouseDown.Y) > 10.0)) { draggedItem = (Model.KeyGroup) this.SelectedItem; if ((draggedItem != null)) { DragDropEffects finalDropEffect = DragDrop.DoDragDrop(this, this.SelectedValue, DragDropEffects.Move); //Checking target is not null and item is dragging(moving) if ((finalDropEffect == DragDropEffects.Move) && (_target != null)) { // A Move drop was accepted if (draggedItem.Gruppenname != _target.Gruppenname) { CopyItem(draggedItem, _target); _target = null; draggedItem = null; } } } } } } catch (Exception ex) { System.Diagnostics.Debug.Print("MouseMove:" + ex.Message.ToString()); } }
private void ExtendedTreeView_Drop(object sender, DragEventArgs e) { try { e.Effects = DragDropEffects.None; e.Handled = true; // Verify that this is a valid drop and then store the drop target Model.KeyGroup TargetItem = GetNearestContainer(e.OriginalSource as UIElement); if (TargetItem != null && draggedItem != null) { _target = TargetItem; e.Effects = DragDropEffects.Move; } } catch (Exception ex) { System.Diagnostics.Debug.Print("Drop:" + ex.Message.ToString()); } }
public dlgGroupEditor(Model.DataBase db, Model.KeyGroup kg) { this.DataContext = KG; InitializeComponent(); }