views:

11

answers:

1

Hello,
We have some xaml:

    <Style TargetType="local:V_RelLine">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="local:V_RelLine">
                <Grid x:Name="LayoutRoot">
                    <VisualStateManager.VisualStateGroups>
                    </VisualStateManager.VisualStateGroups>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Ellipse x:Name="startArrow" Height="20" Width="60" Fill="Green" Stroke="Blue" Visibility="Visible" /> 
                    <Path x:Name="LinePathPart"                               Visibility="Visible" Stroke="Red" StrokeDashArray="2 2" StrokeThickness="2"
                          >
                        <Path.Data>
                            <PathGeometry x:Name="LinePathGeometry" >
                                <PathFigure x:Name="linePathBezierFigure" >
                                    <BezierSegment x:Name="linePathBezierSegment" />
                                </PathFigure>
                            </PathGeometry>
                        </Path.Data>
                    </Path>
                    <Ellipse x:Name="endArrow" Height="20" Width="20" Fill="Red" Stroke="Red" Visibility="Visible" /> 

                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

And in the code behind:

LinePathBezierFigure.StartPoint = startPoint;
Canvas.SetLeft(startArrow, startPoint.X);
Canvas.SetTop(startArrow, startPoint.Y);
/* similar for endArrow */

At runtime, startArrow and endArrow end up at the same point (even though they were set to different locations), as though they ended up at 0,0.
In fact, a subsequent call to Canvas.GetLeft(startArrow) show that it is at 0,0.
What is going on? Why are different objects in the same template, assigned the same coordinates, ending up in different locations?

Thanks for any insight in to this....

A: 

Just a thought but Canvas.Left and Canvas.Top normally only work well when the elements are placed in a Canvas rather than a Grid like you are using currently.

AnthonyWJones
I'm beginning to suspect that is the issue...Why does the Path appear as expected, while the ellipses don't?
Number8
The `StartPoint` of the figure in a `Path` is relative to the containing Path element so it appears as expected. I'm not quite sure how I can simplify the answer further, for `Canvas.Top` and `Canvas.Left` properties to work on the ellipses the ellipses must be children of a `Canvas` element not a `Grid` element.
AnthonyWJones