public void Selected(DesignTemplate s) { this.ClearAllSelection(); s.IsSelected = true; this.SelectedItems.Add(s); s.ZIndex = -1; }
private void DecreaseAllZIndex() { foreach (var s in this.Children) { DesignTemplate step = s as DesignTemplate; if (step == null) { continue; } step.ZIndex--; } }
private static void AreaProperty_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e) { DesignTemplate design = d as DesignTemplate; if (design != null) { if (e.Property == DesignTemplate.WidthProperty) { design.RaisePropertyChanged("Width"); } else if (e.Property == DesignTemplate.HeightProperty) { design.RaisePropertyChanged("Height"); } } }
protected override void OnPreviewMouseDown(System.Windows.Input.MouseButtonEventArgs e) { MultiSeleted = null; if (e.Source == this) { this.ClearAllSelection(); this.MultiSeleted = e.GetPosition(this); if (!this.Children.Contains(this.MultiSeletedRect)) { this.MultiSeletedRect.Height = 0; this.MultiSeletedRect.Width = 0; this.MultiSeletedRect.StrokeThickness = 1; this.MultiSeletedRect.Stroke = Brushes.LightSlateGray; this.MultiSeletedRect.StrokeDashArray = new DoubleCollection { 2, 2 }; this.Children.Add(this.MultiSeletedRect); Canvas.SetLeft(this.MultiSeletedRect, this.MultiSeleted.Value.X); Canvas.SetTop(this.MultiSeletedRect, this.MultiSeleted.Value.Y); } } else if (e.Source is DesignTemplate) { DesignTemplate step = e.Source as DesignTemplate; if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None) { if (step.IsSelected) { this.ClearSelection(step); } else { this.AddSelection(step); } } else if (!step.IsSelected) { this.Selected(step); } } base.OnPreviewMouseDown(e); }
public void AddSelection(DesignTemplate select) { this.AddSelection(new List <DesignTemplate> { select }); }
public void ClearSelection(DesignTemplate design) { design.ZIndex--; this.SelectedItems.Remove(design); design.IsSelected = false; }
protected override void OnMouseMove(MouseEventArgs e) { if (e.LeftButton != MouseButtonState.Pressed) { this.MultiSeleted = null; return; } if (this.MultiSeleted.HasValue) { this.CaptureMouse(); Point start = (Point)this.MultiSeleted; Point end = e.GetPosition(this); end.X = end.X < 0 ? 0 : end.X; end.Y = end.Y < 0 ? 0 : end.Y; if (end.X < start.X) { Canvas.SetLeft(this.MultiSeletedRect, end.X); } if (end.Y < start.Y) { Canvas.SetTop(this.MultiSeletedRect, end.Y); } this.MultiSeletedRect.Height = Math.Abs(end.Y - start.Y); this.MultiSeletedRect.Width = Math.Abs(end.X - start.X); Rect rect = new Rect(start, end); List <DesignTemplate> steps = new List <DesignTemplate>(); foreach (var s in this.Children) { DesignTemplate step = s as DesignTemplate; if (step == null) { continue; } Rect item = VisualTreeHelper.GetDescendantBounds(step); item = step.TransformToAncestor(this).TransformBounds(item); if (step is Step) { if (rect.IntersectsWith(item)) { steps.Add(step); } else { this.ClearSelection(step); } } else { if (rect.Contains(item)) { steps.Add(step); } else { this.ClearSelection(step); } } } if (steps.Count > 0) { this.AddSelection(steps); } } base.OnMouseMove(e); }