Esempio n. 1
0
        // runs from LEAF to ROOT
        private void TreeViewItemExt_MouseMove(object sender, MouseEventArgs e)
        {
            TreeViewItemExt tvie = sender as TreeViewItemExt;

            // drag-n-drop preparation
            if (tvie != null && e != null)
            {
                if (!tvie.IsSelected)
                {
                    return;
                }
                if (e.LeftButton == MouseButtonState.Pressed && !IsDragging)
                {
                    Point pos = e.GetPosition(null);
                    // check if the mouse moved far enough:
                    bool enoughX = Math.Abs(pos.X - mouseMove_startingP.X) > 2 * SystemParameters.MinimumHorizontalDragDistance;
                    bool enoughY = Math.Abs(pos.Y - mouseMove_startingP.Y) > 2 * SystemParameters.MinimumVerticalDragDistance;
                    if (enoughX || enoughY)
                    {
                        this.mouseMove_startingP = pos;
                        this.StartDrag(e);
                    }
                }
            }
        }
Esempio n. 2
0
        private void TreeViewItemExt_Drop(object sender, DragEventArgs e)
        {
            TreeViewItemExt tvie = sender as TreeViewItemExt;

            if (tvie != null && !tvie.IsDragging && e != null)
            {
                IDataObject data = e.Data;
                if (data.GetDataPresent(typeof(Component).ToString()))
                {
                    Component payload = data.GetData(typeof(Component)) as Component;
                    if (payload != null && this.DragNDropCmd != null)
                    {
                        // inform user
                        string           message = string.Format("moving {0}\nto {1}", payload.ToString(), this.Header.ToString());
                        string           caption = "Moving Node";
                        MessageBoxResult answer  = MessageBox.Show(message, caption,
                                                                   MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
                        if (answer == MessageBoxResult.Yes)
                        {
                            // execute drop command
                            this.DragNDropCmd.Execute(new WinUtils.TwoObjects {
                                object1 = payload, object2 = this.Header
                            });
                            e.Handled = true;
                        }

                        // restore the visual style of any containing nodes
                        TreeViewItemExt.RestoreVisualStylesAfterDrop();
                    }
                }
            }
        }
Esempio n. 3
0
        protected override DependencyObject GetContainerForItemOverride()
        {
            TreeViewItemExt container = new TreeViewItemExt();

            container.DragNDropCmd = this.DragNDropCmd;
            container.Tag          = this.Tag + "." + (++this.nr_subnodes).ToString();
            return(container);
        }
Esempio n. 4
0
        private void TreeViewItemExt_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            TreeViewItemExt tvie = sender as TreeViewItemExt;

            if (tvie != null && e != null)
            {
                this.mouseMove_startingP = e.GetPosition(null);
            }
        }
Esempio n. 5
0
        protected override DependencyObject GetContainerForItemOverride()
        {
            TreeViewItemExt container = new TreeViewItemExt();

            container.DragNDropCmd = this.DragNDropCmd;
            this.Counter++;
            container.Tag = this.Counter.ToString();
            return(container);
        }
Esempio n. 6
0
        private void TreeViewItemExt_DragOver(object sender, DragEventArgs e)
        {
            TreeViewItemExt tvie = sender as TreeViewItemExt;

            if (tvie != null && !tvie.IsDragging && e != null)
            {
                IDataObject data = e.Data;
                if (!data.GetDataPresent(typeof(Component).ToString()))
                {
                    e.Effects = DragDropEffects.None;
                    e.Handled = true;
                }
            }
        }
Esempio n. 7
0
        private void TreeViewItemExt_DragLeave(object sender, DragEventArgs e)
        {
            TreeViewItemExt tvie = sender as TreeViewItemExt;

            if (tvie != null && !tvie.IsDragging)
            {
                this.CouldBeDropTarget = false;
                TreeViewItemExt.drop_target_chain.Remove(this);
                System.Windows.Style copy = new Style(typeof(TreeViewItem), this.Style);
                copy.Setters.Add(new Setter(TreeViewItem.BorderBrushProperty, TreeViewItemExt.STANDARD));
                copy.Setters.Add(new Setter(TreeViewItem.BorderThicknessProperty, new Thickness(0)));
                this.Style = copy;
            }
        }
Esempio n. 8
0
        private void ___ICH(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            //disconnected / virtualized item handling
            TreeViewItemExt tvie = SelectedItem as TreeViewItemExt;

            if (tvie != null)
            {
                if (tvie.Header.ToString() == TreeViewExt.DISCONNECTED_ITEM)
                {
                    return;
                }
            }
            //debug
            SelectedItem_ = SelectedItem;
        }
Esempio n. 9
0
        private static void PropagateDragNDropCmd(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TreeViewExt tve = d as TreeViewExt;

            if (tve != null)
            {
                foreach (object item in tve.Items)
                {
                    TreeViewItemExt tvie = tve.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItemExt;
                    if (tvie != null)
                    {
                        tvie.DragNDropCmd = tve.DragNDropCmd;
                    }
                }
            }
        }