Beispiel #1
0
        public DesignerTabVM(DesignerVM parent)
        {
            ParentForm = parent;

            AddItemCommand             = new MyCommand(ExecuteAddItemCommand);
            RemoveItemCommand          = new MyCommand(ExecuteRemoveItemCommand);
            RemoveSelectedItemsCommand = new MyCommand(ExecuteRemoveSelectedItemsCommand);
            ClearSelectedItemsCommand  = new MyCommand(ExecuteClearSelectedItemsCommand);
            ExportItemsCommand         = new MyCommand(ExecuteExportItemsCommand);

            Mediator.Instance.Register(this);
        }
Beispiel #2
0
        protected override void OnDrop(DragEventArgs e)
        {
            base.OnDrop(e);
            DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;

            if (dragObject != null)
            {
                DesignerVM dc = (DataContext as DesignerVM);
                dc.ActiveTab.ClearSelection();
                Point position          = e.GetPosition(this);
                DesignerItemBaseVM item = (DesignerItemBaseVM)Activator.CreateInstance(dragObject.ContentType);
                item.Left       = Math.Max(0, position.X - item.Width / 2); // want drop point to be upper left corner, not center of item
                item.Top        = Math.Max(0, position.Y - item.Height / 2);
                item.IsSelected = true;
                dc.ActiveTab.AddItemCommand.Execute(item);
                dc.ActiveTab.SelectedItem = item;
                // Give the DesignerCanvas focus so it can receive arrow key presses
                this.Focus();
            }
            e.Handled = true;
        }
Beispiel #3
0
        private void UpdateSelection()
        {
            DesignerVM   vm           = (designerCanvas.DataContext as DesignerVM);
            Rect         rubberBand   = new Rect(startPoint.Value, endPoint.Value);
            ItemsControl itemsControl = TreeHelper.TryFindParent <ItemsControl>(designerCanvas);

            int i = 0;

            foreach (DesignerItemBaseVM item in vm.ActiveTab.Items)
            {
                if (item is DesignerItemBaseVM)
                {
                    DependencyObject container = itemsControl.ItemContainerGenerator.ContainerFromItem(item);

                    Rect itemRect   = VisualTreeHelper.GetDescendantBounds((Visual)container);
                    Rect itemBounds = ((Visual)container).TransformToAncestor(designerCanvas).TransformBounds(itemRect);

                    if (rubberBand.Contains(itemBounds))
                    {
                        item.IsSelected = true;
                        // IMPROVE: following always selects first item as ordered in the list, rather than the first
                        //          item encountered by the rubber band selector
                        if (i == 0)
                        {
                            vm.ActiveTab.SelectedItem = item;
                        }
                        i++;
                    }
                    else
                    {
                        if (!(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
                        {
                            item.IsSelected = false;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                // if the canvas ("this") is the source of the event, assume rubberband selecting
                if (e.Source == this)
                {
                    // cache the start point
                    rubberbandSelectionStartPoint = e.GetPosition(this);

                    // unless holding down control, clear the selection
                    DesignerVM dc = (DataContext as DesignerVM);
                    if (!(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
                    {
                        dc.ActiveTab.ClearSelection();
                    }

                    e.Handled = true;
                }
            }
        }