public static void RegisterButtonReaction(this Border control, SolidColorBrush on, SolidColorBrush over, SolidColorBrush down) { control.MouseLeftButtonUp += (object sender, MouseButtonEventArgs e) => { if (control.IsMouseOver) { control.Background = over; } else { control.Background = on; } control.ReleaseMouseCapture(); }; control.MouseLeave += (object sender, MouseEventArgs e) => { if (Mouse.LeftButton == MouseButtonState.Released) { control.Background = on; } }; control.MouseEnter += (object sender, MouseEventArgs e) => { if (Mouse.LeftButton == MouseButtonState.Released) { control.Background = over; } }; control.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => { control.Background = down; control.CaptureMouse(); }; }
public static void RegisterButtonReaction(this Border control, Action on, Action over, Action down) { control.MouseLeftButtonUp += (object sender, MouseButtonEventArgs e) => { if (control.IsMouseOver) { over.TryInvoke(); } else { on.TryInvoke(); } control.ReleaseMouseCapture(); }; control.MouseLeave += (object sender, MouseEventArgs e) => { if (Mouse.LeftButton == MouseButtonState.Released) { on.TryInvoke(); } }; control.MouseEnter += (object sender, MouseEventArgs e) => { if (Mouse.LeftButton == MouseButtonState.Released) { over.TryInvoke(); } }; control.MouseLeftButtonDown += (object sender, MouseButtonEventArgs e) => { down.TryInvoke(); control.CaptureMouse(); }; }
private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { _startPoint = e.GetPosition(this); _border.CaptureMouse(); e.Handled = true; }
private void Btn_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Border tmp = (Border)sender; pos = e.GetPosition(null); tmp.CaptureMouse(); tmp.Cursor = Cursors.Hand; }
void HeaderLeftMouseButtonDown(object sender, MouseButtonEventArgs e) { e.Handled = true; Focus(); _dragWidget.CaptureMouse(); _isMouseCaptured = true; _clickPoint = e.GetPosition(null); //save off the mouse position _oldPosition = new Point(Left, Top); //save off our original window position }
//public void CreatePopup() //{ // Border border = new Border(); // border.BorderBrush = new SolidColorBrush(Colors.Black); // border.BorderThickness = new Thickness(5.0); // StackPanel panel1 = new StackPanel(); // panel1.Background = new SolidColorBrush(Colors.White); // foreach (BaseParam item in data.Properties) // { // StackPanel panel2 = new StackPanel(); // panel2.Orientation = Orientation.Horizontal; // TextBlock paramName = new TextBlock(); // paramName.Text = item.paramName; // paramName.Margin = new Thickness(5.0); // paramName.Width = 200; // panel2.Children.Add(paramName); // panel2.Children.Add(item.DrawParam()); // panel1.Children.Add(panel2); // } // StackPanel panel3 = new StackPanel(); // panel3.Orientation = Orientation.Horizontal; // Button Cancel = new Button(); // Cancel.Content = "Cancel"; // Cancel.Margin = new Thickness(5.0); // //button1.Click += new RoutedEventHandler(button1_Click); // panel3.Children.Add(Cancel); // Button Ok = new Button(); // Ok.Content = "Ok"; // Ok.Margin = new Thickness(5.0); // Ok.Click += new RoutedEventHandler(button1_Click); // panel3.Children.Add(Ok); // panel1.Children.Add(panel3); // border.Child = panel1; // border.MouseLeftButtonDown += new MouseButtonEventHandler(p_MouseLeftButtonDown); // border.MouseMove += new MouseEventHandler(p_MouseMove); // border.MouseLeftButtonUp += new MouseButtonEventHandler(p_MouseLeftButtonUp); // p.Child = border; // p.Width = 600; //} #endregion public void Handle_MouseDown(object sender, MouseEventArgs args) { Border item = sender as Border; mouseVerticalPosition = args.GetPosition(null).Y; mouseHorizontalPosition = args.GetPosition(null).X; isMouseCaptured = true; item.CaptureMouse(); }
public void p_MouseLeftButtonDown(object sender, MouseEventArgs args) { Border item = sender as Border; mouseVerticalPositionEditor = args.GetPosition(null).Y; mouseHorizontalPositionEditor = args.GetPosition(null).X; isMouseCapturedEditor = true; item.CaptureMouse(); }
private void Header_GotMouseCapture(object sender, MouseEventArgs e) { Border HeaderBorder = (Border)this.GetTemplateChild("HeaderBorder"); if (HeaderBorder != null) { HeaderBorder.CaptureMouse(); } }
private void InnerBorderForPointerEvents_PointerPressed_1(object sender, MouseEventArgs e) { Border border = (Border)sender; mouseVerticalPosition = e.GetPosition(null).Y; mouseHorizontalPosition = e.GetPosition(null).X; border.CaptureMouse(); PointerCaptureTextBlock.Text = "Pointer captured"; isMouseCaptured = true; }
private void sceneDot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Border border = sender as Border; if (border != null) { border.BorderBrush = (Brush)FindResource("ValidationBrush5"); isRectDragInProg = true; border.CaptureMouse(); } }
/// <summary> /// 剪辑鼠标点击 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Clip_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Border bor = sender as Border; if (bor != null) { bor.CaptureMouse(); ClipStart_MouseDown_Offset = e.GetPosition(_clipCanvas).X; Start_MouseDown_ClipOffset = _clipStackPanel.Margin.Left; ClipStart_MouseDown_AreaWidth = _clipStackPanel.Margin.Left + _clipStackPanel.ActualWidth; } }
private void ImageClick(object sender, MouseButtonEventArgs e) { Border delta = sender as Border; if (delta.IsMouseCaptured) { return; } delta.BorderBrush = new SolidColorBrush(Chosen); start = e.MouseDevice.GetPosition(MainContainer); delta.CaptureMouse(); }
private void SetViewboxMaximized(object sender, MouseButtonEventArgs e) { Border outer = sender as Border; Border inner = outer.Child as Border; if (inner != null) { inner.CaptureMouse(); outer.Child = null; viewSpecimen.Child = inner; inner.BorderBrush = new SolidColorBrush(Color.FromRgb(0x33, 0x99, 0xff)); fontList.SelectedIndex = (int)outer.Tag; fontList.ScrollIntoView(fontList.SelectedItem); } }
private void OnMouseDown(object sender, RoutedEventArgs e) { var s = e as System.Windows.Input.MouseButtonEventArgs; if (s != null) { isDraging = true; startPoint = s.GetPosition(parentCanvas); var startX = Canvas.GetLeft(parentGrid); var startY = Canvas.GetTop(parentGrid); var width = parentGrid.ActualWidth; var height = parentGrid.ActualHeight; startRect = new Rect(startX, startY, width, height); } border.CaptureMouse(); }
private void selectionBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (MoveSelection) { _lastMousePosition = e.GetPosition(this); _isMoving = true; if (_selectionBorder != null) { _selectionBorder.CaptureMouse(); } e.Handled = true; } }
private void Border_MouseDown(object sender, MouseButtonEventArgs e) { curNodeBorder = sender as Border; if (currMod != Mods[Key.None] && currMod != Mods[cnsAddNode]) { MainOperations[currMod].Invoke(sender); } if (currMod == Mods[Key.None]) { curNodeBorder.CaptureMouse(); } if (firstPressed == Key.None && currMod != Mods[cnsAddEdge] && currMod != Mods[cnsRenameNode]) { currMod = Mods[Key.None]; } e.Handled = true; }
/// <summary> /// 放大窗口 /// </summary> private void Window_Widen(object sender, MouseEventArgs e) { if (_IsWiden) { if (sender is Border border) { sizeGap = border; sizeGap.CaptureMouse(); Window window = Window.GetWindow(sizeGap); double width = e.GetPosition(window).X; double height = e.GetPosition(window).Y; if (width > window.MinWidth && height > window.MinHeight) { window.Width = width; window.Height = height; } } } }
// //鼠标移动 // private void Border_MouseMove(object sender, MouseEventArgs e) { Border b = (Border)sender; if (isWiden) { b.CaptureMouse(); double newWidth = e.GetPosition(this).X + 5; double newheight = e.GetPosition(this).Y + 5; if (newWidth > 0) { this.Width = newWidth; } if (newheight > 0) { this.Height = newheight; } } }
private void Border_MouseMove(object sender, MouseEventArgs e) { Border b = (Border)sender; if (isWiden) { Window win = (Window)((FrameworkElement)sender).TemplatedParent; b.CaptureMouse(); double newWidth = e.GetPosition(win).X + 5; double newheight = e.GetPosition(win).Y + 5; if (newWidth > 0) { win.Width = newWidth; } if (newheight > 0) { win.Height = newheight; } } }
private void MainBorderOnMouseDown(object sender, MouseButtonEventArgs mouseButtonEventArgs) { if (isMoving || IsCollapsed) { isMoving = false; return; } var point = mouseButtonEventArgs.GetPosition(mainBorder); var direction = GetDirection(point); if (direction == ResizeDirection.None) { return; } OnResizeBegin(); mainBorder.CaptureMouse(); SetStartBounds(); resizeDirection = direction; startPoint = point; SetCursor(resizeDirection); }
void OnSpellMouseDown(object sender, MouseButtonEventArgs e) { Border spell = sender as Border; if (spell != null) { // Initiate drag _floating.Background = spell.Background; _floating.BorderBrush = spell.BorderBrush; _floating.Visibility = Visibility.Visible; _offset = e.GetPosition(spell); Point canvasPos = e.GetPosition(_canvas); Canvas.SetLeft(_floating, canvasPos.X - _offset.X); Canvas.SetTop(_floating, canvasPos.Y - _offset.Y); if (_floating.CaptureMouse()) { _floating.MouseMove += OnFloatingDrag; _floating.MouseUp += OnFloatingDrop; } } }
void resize_MouseDown(object sender, MouseButtonEventArgs e) { resize.CaptureMouse(); isResizeWork = true; oldPoint = e.GetPosition(this); }
private Border CreateControlPoint(ControlPoint controlPoint) { var point = new Border(); point.MouseDown += (s, e) => { point.CaptureMouse(); ControlPointMouseDown?.Invoke(this, controlPoint); }; point.MouseLeave += (s, e) => { if (e.LeftButton == MouseButtonState.Released) { point.ReleaseMouseCapture(); ControlPointMouseUp?.Invoke(this, controlPoint); } }; Binding binding = new Binding() { //Source = designItemModel, Path = new PropertyPath("ControlPointVisibility"), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; BindingOperations.SetBinding(point, VisibilityProperty, binding); point.Width = 10; point.Height = 10; point.CornerRadius = new System.Windows.CornerRadius() { TopLeft = 10, TopRight = 10, BottomLeft = 10, BottomRight = 10 }; point.SetCurrentValue(Panel.ZIndexProperty, 2); point.Background = Project1UIColor.Get("#6495ED"); var cursorEnter = Cursors.Hand; switch (controlPoint) { case ControlPoint.LeftTop: cursorEnter = Cursors.SizeNWSE; point.VerticalAlignment = System.Windows.VerticalAlignment.Top; point.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; point.Margin = new System.Windows.Thickness(-5, -5, 0, 0); break; case ControlPoint.RightTop: cursorEnter = Cursors.SizeNESW; point.VerticalAlignment = System.Windows.VerticalAlignment.Top; point.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; point.Margin = new System.Windows.Thickness(0, -5, -5, 0); break; case ControlPoint.LeftBottom: cursorEnter = Cursors.SizeNESW; point.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; point.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; point.Margin = new System.Windows.Thickness(-5, 0, 0, -5); break; case ControlPoint.RightBottom: cursorEnter = Cursors.SizeNWSE; point.VerticalAlignment = System.Windows.VerticalAlignment.Bottom; point.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; point.Margin = new System.Windows.Thickness(0, 0, -5, -5); break; } point.Cursor = cursorEnter; return(point); }
public SheetTabControl() { this.Background = SystemColors.ControlBrush; this.BorderColor = Colors.DeepSkyBlue; this.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(20) }); this.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(20) }); this.ColumnDefinitions.Add(new ColumnDefinition { }); this.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(30) }); this.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(5) }); Border pleft = new ArrowBorder(this) { Child = new Polygon() { Points = new PointCollection( new Point[] { new Point(6, 0), new Point(0, 5), new Point(6, 10), }), Fill = SystemColors.ControlDarkDarkBrush, HorizontalAlignment = System.Windows.HorizontalAlignment.Center, VerticalAlignment = System.Windows.VerticalAlignment.Center, Margin = new Thickness(4, 0, 0, 0), }, Background = SystemColors.ControlBrush, }; Border pright = new ArrowBorder(this) { Child = new Polygon() { Points = new PointCollection( new Point[] { new Point(0, 0), new Point(6, 5), new Point(0, 10), }), Fill = SystemColors.ControlDarkDarkBrush, HorizontalAlignment = System.Windows.HorizontalAlignment.Center, VerticalAlignment = System.Windows.VerticalAlignment.Center, Margin = new Thickness(0, 0, 4, 0), }, Background = SystemColors.ControlBrush, }; this.canvas.RenderTransform = new TranslateTransform(0, 0); this.Children.Add(this.canvas); Grid.SetColumn(this.canvas, 2); this.Children.Add(pleft); Grid.SetColumn(pleft, 0); this.Children.Add(pright); Grid.SetColumn(pright, 1); BitmapImage imageSource = new BitmapImage(); BitmapImage imageHoverSource = new BitmapImage(); imageSource.BeginInit(); imageSource.StreamSource = new System.IO.MemoryStream(unvell.ReoGrid.Properties.Resources.NewBuildDefinition_8952_inactive_png); imageSource.EndInit(); imageHoverSource.BeginInit(); imageHoverSource.StreamSource = new System.IO.MemoryStream(unvell.ReoGrid.Properties.Resources.NewBuildDefinition_8952_png); imageHoverSource.EndInit(); newSheetImage = new Image() { Source = imageSource, HorizontalAlignment = System.Windows.HorizontalAlignment.Center, VerticalAlignment = System.Windows.VerticalAlignment.Center, Margin = new Thickness(2), Cursor = System.Windows.Input.Cursors.Hand, }; newSheetImage.MouseEnter += (s, e) => newSheetImage.Source = imageHoverSource; newSheetImage.MouseLeave += (s, e) => newSheetImage.Source = imageSource; newSheetImage.MouseDown += (s, e) => { if (this.NewSheetClick != null) { this.NewSheetClick(this, null); } }; this.Children.Add(newSheetImage); Grid.SetColumn(newSheetImage, 3); Border rightThumb = new Border { Child = new RightThumb(this), Cursor = System.Windows.Input.Cursors.SizeWE, Background = SystemColors.ControlBrush, Margin = new Thickness(0, 1, 0, 0), HorizontalAlignment = System.Windows.HorizontalAlignment.Center, }; this.Children.Add(rightThumb); Grid.SetColumn(rightThumb, 4); this.scrollTimer = new System.Windows.Threading.DispatcherTimer() { Interval = new TimeSpan(0, 0, 0, 0, 10), }; scrollTimer.Tick += (s, e) => { var tt = this.canvas.Margin.Left; if (this.scrollLeftDown) { if (tt < 0) { tt += 5; if (tt > 0) { tt = 0; } } } else if (this.scrollRightDown) { double max = this.ColumnDefinitions[2].ActualWidth - this.canvas.Width; if (tt > max) { tt -= 5; if (tt < max) { tt = max; } } } if (this.canvas.Margin.Left != tt) { this.canvas.Margin = new Thickness(tt, 0, 0, 0); } }; pleft.MouseDown += (s, e) => { this.scrollRightDown = false; if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed) { this.scrollLeftDown = true; this.scrollTimer.IsEnabled = true; } else if (e.RightButton == System.Windows.Input.MouseButtonState.Pressed) { if (this.SheetListClick != null) { this.SheetListClick(this, null); } } }; pleft.MouseUp += (s, e) => { this.scrollTimer.IsEnabled = false; this.scrollLeftDown = false; }; pright.MouseDown += (s, e) => { this.scrollLeftDown = false; if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed) { this.scrollRightDown = true; this.scrollTimer.IsEnabled = true; } else if (e.RightButton == System.Windows.Input.MouseButtonState.Pressed) { if (this.SheetListClick != null) { this.SheetListClick(this, null); } } }; pright.MouseUp += (s, e) => { this.scrollTimer.IsEnabled = false; this.scrollRightDown = false; }; rightThumb.MouseDown += (s, e) => { this.splitterMoving = true; rightThumb.CaptureMouse(); }; rightThumb.MouseMove += (s, e) => { if (this.splitterMoving) { if (this.SplitterMoving != null) { this.SplitterMoving(this, null); } } }; rightThumb.MouseUp += (s, e) => { this.splitterMoving = false; rightThumb.ReleaseMouseCapture(); }; }
public override void OnApplyTemplate() { base.OnApplyTemplate(); Resizer resLeftAnchor = GetTemplateChild("PART_LeftAnchor") as Resizer; Resizer resTopAnchor = GetTemplateChild("PART_TopAnchor") as Resizer; Resizer resBottomAnchor = GetTemplateChild("PART_BottomAnchor") as Resizer; Resizer resRightAnchor = GetTemplateChild("PART_RightAnchor") as Resizer; Resizer resLeftTopAnchor = GetTemplateChild("PART_LeftTopAnchor") as Resizer; Resizer resLeftBottomAnchor = GetTemplateChild("PART_LeftBottomAnchor") as Resizer; Resizer resRightTopAnchor = GetTemplateChild("PART_RightTopAnchor") as Resizer; Resizer resRightBottomAnchor = GetTemplateChild("PART_RightBottomAnchor") as Resizer; //Resizer resMoveAnchor = GetTemplateChild("PART_MoveAnchor") as Resizer; Border resMoveAnchor = GetTemplateChild("PART_MoveAnchor") as Border; if (resLeftAnchor != null) { resLeftAnchor.DragDelta += (s, e) => { double delta = Math.Max(MinWidth, Width - e.HorizontalChange) - Width; this.Left -= delta; this.Width += delta; } } ; if (resRightAnchor != null) { resRightAnchor.DragDelta += (s, e) => { double delta = Math.Max(MinWidth, Width + e.HorizontalChange) - Width; this.Width += delta; } } ; if (resTopAnchor != null) { resTopAnchor.DragDelta += (s, e) => { double delta = Math.Max(MinHeight, Height - e.VerticalChange) - Height; this.Top -= delta; this.Height += delta; } } ; if (resBottomAnchor != null) { resBottomAnchor.DragDelta += (s, e) => { double delta = Math.Max(MinHeight, Height + e.VerticalChange) - Height; this.Height += delta; } } ; if (resLeftTopAnchor != null) { resLeftTopAnchor.DragDelta += (s, e) => { double delta = Math.Max(MinWidth, Width - e.HorizontalChange) - Width; this.Left -= delta; this.Width += delta; delta = Math.Max(MinHeight, Height - e.VerticalChange) - Height; this.Top -= delta; this.Height += delta; } } ; if (resLeftBottomAnchor != null) { resLeftBottomAnchor.DragDelta += (s, e) => { double delta = Math.Max(MinWidth, Width - e.HorizontalChange) - Width; this.Left -= delta; this.Width += delta; delta = Math.Max(MinHeight, Height + e.VerticalChange) - Height; this.Height += delta; } } ; if (resRightTopAnchor != null) { resRightTopAnchor.DragDelta += (s, e) => { double delta = Math.Max(MinWidth, Width + e.HorizontalChange) - Width; this.Width += delta; delta = Math.Max(MinHeight, Height - e.VerticalChange) - Height; this.Top -= delta; this.Height += delta; } } ; if (resRightBottomAnchor != null) { resRightBottomAnchor.DragDelta += (s, e) => { double delta = Math.Max(MinWidth, Width + e.HorizontalChange) - Width; this.Width += delta; delta = Math.Max(MinHeight, Height + e.VerticalChange) - Height; this.Height += delta; } } ; if (resMoveAnchor != null) { bool isMouseDown = false; Point ptStartDrag = new Point(); resMoveAnchor.MouseLeftButtonDown += (s, e) => { isMouseDown = true; ptStartDrag = e.GetPosition(s as IInputElement); resMoveAnchor.CaptureMouse(); }; resMoveAnchor.MouseMove += (s, e) => { if (isMouseDown && resMoveAnchor.IsMouseCaptured) { Point ptMouseMove = e.GetPosition(s as IInputElement); if (Math.Abs(ptMouseMove.X - ptStartDrag.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(ptMouseMove.Y - ptStartDrag.Y) > SystemParameters.MinimumVerticalDragDistance) { isMouseDown = false; resMoveAnchor.ReleaseMouseCapture(); HandleMove(); } } }; resMoveAnchor.MouseLeftButtonUp += (s, e) => { isMouseDown = false; resMoveAnchor.ReleaseMouseCapture(); }; } var pupupButton = GetTemplateChild("PART_ShowContextMenuButton") as FrameworkElement; if (pupupButton != null) { pupupButton.MouseLeftButtonDown += (s, e) => { e.Handled = OpenContextMenu(s as Border, e.GetPosition(s as IInputElement)); } } ; var titleAnchor = GetTemplateChild("PART_MoveAnchor") as FrameworkElement; if (titleAnchor != null) { titleAnchor.MouseRightButtonDown += (s, e) => { e.Handled = OpenContextMenu(s as Border, e.GetPosition(s as IInputElement)); } } ; base.OnApplyTemplate(); }
private FrameworkElement CreateControl() { if (grid != null) { return(grid); } grid = new Grid { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(Left, Top, 0, 0) }; grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength() }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength() }); grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength() }); Brush background = Application.Current.FindResource("BackgroundMainWindow") as Brush ?? Brushes.White; Brush borderBrush = Application.Current.FindResource("BorderThinBrush") as Brush ?? Brushes.Black; Grid g = new Grid(); g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }); g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); g.RowDefinitions.Add(new RowDefinition { Height = new GridLength(2, GridUnitType.Star) }); for (int r = 0; r < g.RowDefinitions.Count; r++) { System.Windows.Shapes.Ellipse e = new System.Windows.Shapes.Ellipse { Width = 3, Height = 3, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Fill = borderBrush }; Grid.SetRow(e, r); g.Children.Add(e); } b = new Border { VerticalAlignment = VerticalAlignment.Top, BorderThickness = new Thickness(0, 1, 1, 1), BorderBrush = borderBrush, Background = background, Width = 12, Height = 24, Cursor = System.Windows.Input.Cursors.Hand, Child = g }; b.MouseDown += (o, e) => { startPoint = e.GetPosition(ChartPanel); margin = grid.Margin; if (e.ClickCount > 1) { b.ReleaseMouseCapture(); ChartControl.OnIndicatorsHotKey(this, null); } else { b.CaptureMouse(); } }; b.MouseUp += (o, e) => { b.ReleaseMouseCapture(); }; b.MouseMove += (o, e) => { if (!b.IsMouseCaptured || grid == null || ChartPanel == null) { return; } Point newPoint = e.GetPosition(ChartPanel); grid.Margin = new Thickness { Left = Math.Max(0, Math.Min(margin.Left + (newPoint.X - startPoint.X), ChartPanel.ActualWidth - grid.ActualWidth)), Top = Math.Max(0, Math.Min(margin.Top + (newPoint.Y - startPoint.Y), ChartPanel.ActualHeight - grid.ActualHeight)) }; Left = grid.Margin.Left; Top = grid.Margin.Top; }; Grid.SetColumn(b, 1); grid.Children.Add(b); Grid contentGrid = new Grid(); List <XElement> elements = SortElements(XElement.Parse(SelectedTypes.ToString())); int column = 0; int count = 0; FontFamily fontFamily = Application.Current.Resources["IconsFamily"] as FontFamily; Style style = Application.Current.Resources["LinkButtonStyle"] as Style; //ToolBar tb = new ToolBar(); while (count < elements.Count) { if (contentGrid.ColumnDefinitions.Count <= column) { contentGrid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); } for (int j = 0; j < NumberOfRows && count < elements.Count; j++) { if (contentGrid.RowDefinitions.Count <= j) { contentGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); } XElement element = elements[count]; try { DrawingTools.DrawingTool dt = Core.Globals.AssemblyRegistry[element.Attribute("Assembly").Value].CreateInstance(element.Name.ToString()) as DrawingTools.DrawingTool; if (dt != null && dt.DisplayOnChartsMenus) { Button bb = new Button { Content = dt.Icon ?? Gui.Tools.Icons.DrawPencil, ToolTip = dt.DisplayName, Style = style, FontFamily = fontFamily, FontSize = 16, FontStyle = FontStyles.Normal, Margin = new Thickness(3), Padding = new Thickness(3) }; Grid.SetRow(bb, j); Grid.SetColumn(bb, column); bb.Click += (sender, args) => { if (ChartControl != null) { ChartControl.TryStartDrawing(dt.GetType().FullName); } }; contentGrid.Children.Add(bb); //tb.Items.Add(bb); count++; } else { elements.RemoveAt(j); j--; } } catch (Exception e) { elements.RemoveAt(j); j--; Cbi.Log.Process(typeof(Custom.Resource), "NinjaScriptTileError", new object[] { element.Name.ToString(), e }, LogLevel.Error, LogCategories.NinjaScript); } } column++; } Border tileHolder = new Border { Cursor = System.Windows.Input.Cursors.Arrow, Background = Application.Current.FindResource("BackgroundMainWindow") as Brush, BorderThickness = new Thickness((double)(Application.Current.FindResource("BorderThinThickness") ?? 1)), BorderBrush = Application.Current.FindResource("BorderThinBrush") as Brush, Child = contentGrid }; grid.Children.Add(tileHolder); if (IsVisibleOnlyFocused) { Binding binding = new Binding("IsActive") { Source = ChartControl.OwnerChart, Converter = Application.Current.FindResource("BoolToVisConverter") as IValueConverter }; grid.SetBinding(UIElement.VisibilityProperty, binding); } return(grid); }