示例#1
0
        private void SuperTypeTree_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                Point currentPosition = e.GetPosition(SuperTypeTree);

                // Note: This should be based on some accessibility number and not just 2 pixels
                if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > 2.0) ||
                    (Math.Abs(currentPosition.Y - _lastMouseDown.Y) > 2.0))
                {
                    var selectedItem = (DmSuperTyp)SuperTypeTree.SelectedItem;
                    {
                        TreeViewItem container = GetContainerFromSuperType(selectedItem);
                        if (container != null)
                        {
                            DragDropEffects finalDropEffect = DragDrop.DoDragDrop(container, selectedItem, DragDropEffects.Move);
                            if ((finalDropEffect == DragDropEffects.Move) && (_targetSuperType != null))
                            {
                                // A Move drop was accepted
                                selectedItem.Move(_targetSuperType);
                                //selectedItem.Parent.Childs.Remove(selectedItem);
                                //_targetSuperType.Childs.Add(selectedItem);
                                _targetSuperType = null;
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        private TreeViewItem GetContainerFromSuperType(DmSuperTyp superType)
        {
            var _stack = new Stack <DmSuperTyp>();

            _stack.Push(superType);
            var parent = superType.Parent;

            while (parent != null)
            {
                _stack.Push(parent);
                parent = parent.Parent;
            }

            ItemsControl container = SuperTypeTree;

            while ((_stack.Count > 0) && (container != null))
            {
                var top = _stack.Pop();
                container = (ItemsControl)container.ItemContainerGenerator.ContainerFromItem(top);
            }

            return(container as TreeViewItem);
        }
示例#3
0
        private void SuperTypeTree_Drop(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.None;
            e.Handled = true;


            // Verify that this is a valid drop and then store the drop target
            TreeViewItem container = GetNearestContainer(e.OriginalSource as UIElement);

            if (container != null)
            {
                var sourceSuperType = (DmSuperTyp)e.Data.GetData(typeof(DmSuperTyp));
                var targetSuperType = (DmSuperTyp)container.Header;
                if ((sourceSuperType != null) && (targetSuperType != null))
                {
                    if (!targetSuperType.Childs.Contains(sourceSuperType))
                    {
                        _targetSuperType = targetSuperType;
                        e.Effects        = DragDropEffects.Move;
                    }
                }
            }
        }