/// <summary> /// Adds new shape for <see cref="HudBaseToolViewModel"/> to shapes /// </summary> /// <param name="toolViewModel">ViewModel of tool to add</param> private void AddTool(HudBaseToolViewModel toolViewModel) { var shape = new RadDiagramShape() { DataContext = toolViewModel, StrokeThickness = 0, BorderThickness = new Thickness(0), IsEnabled = true, Background = null, IsRotationEnabled = false, Padding = new Thickness(0), IsManipulationEnabled = false, IsDraggingEnabled = true, IsConnectorsManipulationEnabled = false, ZIndex = ToolElementZIndex }; AttachToolBar(shape, toolViewModel as IHudToolBar); SetReadOnly(shape, IsReadOnly, toolViewModel); SetWidthBinding(shape, toolViewModel); SetHeightBinding(shape, toolViewModel); SetPositionBinding(shape, toolViewModel); SetIsSelectedBinding(shape, toolViewModel); SetIsVisibleBinding(shape, toolViewModel); AssociatedObject.AddShape(shape); RemovableShapes.Add(shape); }
/// <summary> /// Removes shape for <see cref="HudBaseToolViewModel"/> from shapes /// </summary> /// <param name="toolViewModel">ViewModel of tool to add</param> private void RemoveTool(HudBaseToolViewModel toolViewModel) { if (AssociatedObject == null || toolViewModel == null) { return; } var shapes = AssociatedObject.Shapes.OfType <RadDiagramShape>().Where(x => ReferenceEquals(x.DataContext, toolViewModel)).ToArray(); shapes.ForEach(shape => AssociatedObject.RemoveShape(shape)); }
/// <summary> /// Makes shape with tool read only /// </summary> /// <param name="shape">Shape</param> /// <param name="isReadOnly"></param> private void SetReadOnly(RadDiagramShape shape, bool isReadOnly, HudBaseToolViewModel toolViewModel) { if (shape == null || toolViewModel == null) { return; } shape.IsEditable = !isReadOnly; shape.IsResizingEnabled = toolViewModel.IsResizable && !isReadOnly; shape.IsDraggingEnabled = !isReadOnly; }
protected static void SetIsVisibleBinding(RadDiagramShape shape, HudBaseToolViewModel viewModel) { var converter = new BoolToVisibilityConverter(); SetBinding(shape, UIElement.VisibilityProperty, viewModel, nameof(HudBaseToolViewModel.IsVisible), BindingMode.OneWay, converter); }
protected static void SetIsSelectedBinding(RadDiagramShape shape, HudBaseToolViewModel viewModel) { SetBinding(shape, RadDiagramItem.IsSelectedProperty, viewModel, nameof(HudBaseToolViewModel.IsSelected), viewModel.IsSelectedBindingMode); }
protected static void SetHeightBinding(RadDiagramShape shape, HudBaseToolViewModel viewModel) { SetBinding(shape, FrameworkElement.HeightProperty, viewModel, nameof(HudBaseToolViewModel.Height)); }
protected static void SetOpacityBinding(RadDiagramShape shape, HudBaseToolViewModel viewModel) { SetBinding(shape, UIElement.OpacityProperty, viewModel, nameof(HudBaseToolViewModel.Opacity)); }
protected static void SetPositionBinding(RadDiagramShape shape, HudBaseToolViewModel viewModel) { SetBinding(shape, RadDiagramItem.PositionProperty, viewModel, nameof(HudBaseToolViewModel.Position)); }