<ControlTemplate x:Key="Circle"> <Grid Name="RootElement" RenderTransformOrigin="0.5,0.5" > <Grid.RenderTransform> <ScaleTransform ScaleX="1" ScaleY="1" /> </Grid.RenderTransform> <VisualStateManager.VisualStateGroups> <VisualStateGroup Name="CommonStates"> <VisualState Name="Normal"> <Storyboard> <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" To="1" Duration="0:0:0.1" /> <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" To="1" Duration="0:0:0.1" /> </Storyboard> </VisualState> <VisualState Name="MouseOver"> <Storyboard> <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" To="1.5" Duration="0:0:0.1" /> <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" To="1.5" Duration="0:0:0.1" /> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Ellipse Height="{Binding Symbol.Size}" Width="{Binding Symbol.Size}" Fill="{Binding Symbol.Color}" Stroke="Black"> </Ellipse> </Grid> </ControlTemplate>
<ControlTemplate x:Key="Arrow"> <Grid Name="RootElement" RenderTransformOrigin="0.5,0.5" > <Grid.RenderTransform> <ScaleTransform ScaleX="1" ScaleY="1" /> </Grid.RenderTransform> <VisualStateManager.VisualStateGroups> <VisualStateGroup Name="CommonStates"> <VisualState Name="Normal"> <Storyboard> <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" To="1" Duration="0:0:0.1" /> <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" To="1" Duration="0:0:0.1" /> </Storyboard> </VisualState> <VisualState Name="MouseOver"> <Storyboard> <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" To="1.5" Duration="0:0:0.1" /> <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="RootElement" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" To="1.5" Duration="0:0:0.1" /> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <custom:Arrow Size="{Binding Symbol.Size}" Fill="{Binding Symbol.Color}" Stroke="Black" RotationAngle="0"> </custom:Arrow> </Grid> </ControlTemplate>
public class Arrow : Shape { public Arrow() { } public static readonly DependencyProperty SizeProperty = DependencyProperty.Register("Size", typeof(Double), typeof(Arrow)); public static readonly DependencyProperty RotationAngleProperty = DependencyProperty.Register("RotationAngle", typeof(Double), typeof(Arrow), new PropertyMetadata(0.0d)); public double Size { get { return (double)this.GetValue(SizeProperty); } set { this.SetValue(SizeProperty, value); } } public double RotationAngle { get { return (double)this.GetValue(RotationAngleProperty); } set { this.SetValue(RotationAngleProperty, value); } } protected override Geometry DefiningGeometry { get { double oneThird = this.Size / 3; double twoThirds = (this.Size * 2) / 3; double oneHalf = this.Size / 2; Point p1 = new Point(0.0d, oneThird); Point p2 = new Point(0.0d, twoThirds); Point p3 = new Point(oneHalf, twoThirds); Point p4 = new Point(oneHalf, this.Size); Point p5 = new Point(this.Size, oneHalf); Point p6 = new Point(oneHalf, 0); Point p7 = new Point(oneHalf, oneThird); List<PathSegment> segments = new List<PathSegment>(3); segments.Add(new LineSegment(p1, true)); segments.Add(new LineSegment(p2, true)); segments.Add(new LineSegment(p3, true)); segments.Add(new LineSegment(p4, true)); segments.Add(new LineSegment(p5, true)); segments.Add(new LineSegment(p6, true)); segments.Add(new LineSegment(p7, true)); List<PathFigure> figures = new List<PathFigure>(1); PathFigure pf = new PathFigure(p1, segments, true); figures.Add(pf); RotateTransform rt = new RotateTransform(this.RotationAngle); Geometry g = new PathGeometry(figures, FillRule.EvenOdd, rt); return g; } } }
Solved! Go to Solution.
I don't see how your Size DP connects to your DefiningGeometry. You should define the Size change handler to update it.
public static readonly DependencyProperty SizeProperty = DependencyProperty.Register("Size", typeof(Double), typeof(MapShape), new UIPropertyMetadata(new PropertyChangedCallback(SizeChanged)));
private static void SizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { MapShape shape = (MapShape)d; shape.InvalidateVisual(); }