private void EnsureShapePropertyControlUpdated(object propertyName) { PaintDotNet.UI.FrameworkElement element; Property property = this.TryGetChanges().ShapePropertySchema[propertyName]; if (!(property is DoubleVectorProperty)) { throw new InternalErrorException(); } if (!this.propertyNameToControlMap.TryGetValue(propertyName, out element)) { CircleHandleDrawing drawing = new CircleHandleDrawing(); HandleElement handleElement = new HandleElement(drawing); handleElement.SetBinding(DrawingElement.ScaleProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay); handleElement.SetBinding <double, PaintDotNet.UI.Thickness>(DrawingElement.PaddingProperty, this, PropertyPathUtil.Combine(ToolUICanvas.CanvasViewProperty, CanvasView.CanvasHairWidthProperty), BindingMode.OneWay, new Func <double, PaintDotNet.UI.Thickness>(ShapesToolUI.GetHandlePadding)); handleElement.SetBinding <bool, Cursor>(PaintDotNet.UI.FrameworkElement.CursorProperty, this, new PaintDotNet.ObjectModel.PropertyPath(UIElement.IsMouseCaptureWithinProperty), BindingMode.OneWay, delegate(bool imcw) { if (!imcw) { return(this.handCursor); } return(this.handMouseDownCursor); }); DependencyFunc <ShapesToolChanges, SizeDouble, PointDouble> func = new DependencyFunc <ShapesToolChanges, SizeDouble, PointDouble>((stc, actsz) => GetShapePropertyControlCanvasOffset(propertyName, stc, actsz)); func.SetArgInput <ShapesToolChanges>(1, this.toolChanges); func.SetArgInput(2, handleElement, new PaintDotNet.ObjectModel.PropertyPath(PaintDotNet.UI.FrameworkElement.ActualSizeProperty)); handleElement.SetBinding(PaintDotNet.UI.Controls.Canvas.LeftProperty, func, new PaintDotNet.ObjectModel.PropertyPath(func.GetValueProperty().Name + ".X", Array.Empty <object>()), BindingMode.OneWay); handleElement.SetBinding(PaintDotNet.UI.Controls.Canvas.TopProperty, func, new PaintDotNet.ObjectModel.PropertyPath(func.GetValueProperty().Name + ".Y", Array.Empty <object>()), BindingMode.OneWay); DependencyObjectTagger.Set <DependencyFunc <ShapesToolChanges, SizeDouble, PointDouble> >(handleElement, shapePropertyControlCanvasOffsetTagKey, func); AnimationStateHelper helper = new AnimationStateHelper { Element = handleElement }; helper.EnableAnimations += delegate(object <sender>, EventArgs <e>) { AnimatedDouble sourceObject = new AnimatedDouble(1.0); handleElement.SetBinding(UIElement.OpacityProperty, sourceObject, new PaintDotNet.ObjectModel.PropertyPath(AnimatedValue <double> .ValuePropertyName, Array.Empty <object>()), BindingMode.OneWay); sourceObject.AnimateRawValue((s, v) => InitializeHandleOpacityStoryboard(s, v, 0.5), null); DependencyObjectTagger.Set <AnimatedDouble>(handleElement, shapePropertyControlOpacityAnimationTagKey, sourceObject); }; helper.DisableAnimations += delegate(object <sender>, EventArgs <e>) { AnimatedDouble num; handleElement.ClearBinding(UIElement.OpacityProperty); if (DependencyObjectTagger.TryGet <AnimatedDouble>(handleElement, shapePropertyControlOpacityAnimationTagKey, out num)) { num.StopAnimation(); num.Dispose(); DependencyObjectTagger.Remove(handleElement, shapePropertyControlOpacityAnimationTagKey); } }; DependencyObjectTagger.Set <AnimationStateHelper>(handleElement, shapePropertyControlOpacityAnimationStateHelperTagKey, helper); ClickDragBehavior.SetAllowClick(handleElement, false); ClickDragBehavior.SetAllowDoubleClick(handleElement, false); ClickDragBehavior.SetAllowDrag(handleElement, true); ClickDragBehavior.SetIsEnabled(handleElement, true); SetShapePropertyName(handleElement, propertyName); SetHandleType(handleElement, ShapesToolHandleType.ShapeProperty); base.AddVisualChild(handleElement); element = handleElement; this.propertyNameToControlMap.Add(propertyName, element); } }
private void EnsureShapePropertyControlRemoved(object propertyName) { PaintDotNet.UI.FrameworkElement element; if (this.propertyNameToControlMap.TryGetValue(propertyName, out element)) { DependencyFunc <ShapesToolChanges, SizeDouble, PointDouble> func; AnimationStateHelper helper; element.ClearValue(ShapePropertyNameProperty); element.ClearAllBindings(); base.RemoveVisualChild(element); this.propertyNameToControlMap.Remove(propertyName); if (DependencyObjectTagger.TryGet <DependencyFunc <ShapesToolChanges, SizeDouble, PointDouble> >(element, shapePropertyControlCanvasOffsetTagKey, out func)) { func.ClearAllBindings(); DependencyObjectTagger.Remove(element, shapePropertyControlCanvasOffsetTagKey); } if (DependencyObjectTagger.TryGet <AnimationStateHelper>(element, shapePropertyControlOpacityAnimationStateHelperTagKey, out helper)) { DependencyObjectTagger.Remove(element, shapePropertyControlOpacityAnimationStateHelperTagKey); helper.Dispose(); } } }