tags:

views:

1111

answers:

2

I want to place this User control at Canvas.Left="168" Canvas.Top="213".

However, the control appreas at a corner.What should I do?

If I put the values at the point of usage, for this class the values are returned as NaN In that case how can I get the correct Left, Top Values?

Usage:

<Canvas x:Name="DesignerCanvas"
        ClipToBounds="True"
        SnapsToDevicePixels="True">
<Gr:BareNode />
</Canvas>

UserControl:

<UserControl x:Class="DiagramDesigner.BareNode"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;

<Grid>
    <ContentControl Width="50"
                  Height="50"
                  Padding="2"    
                  Canvas.Left="168" Canvas.Top="213">
        <Ellipse IsHitTestVisible="False" >
            <Shape.Fill>
                <RadialGradientBrush Center="0.2, 0.2" GradientOrigin="0.2, 0.2" RadiusX="0.8" RadiusY="0.8">
                    <GradientStop Color="LightBlue" Offset="0"/>
                    <GradientStop Color="Blue" Offset="0.9"/>
                </RadialGradientBrush>
            </Shape.Fill>
        </Ellipse>
    </ContentControl>
   </Grid>
</UserControl>
+2  A: 

I'm not sure if you tried this or not, but just from looking at the XAML it appears that you are trying to set the position of the user control inside the user control. That won't work. You need to put it where you use the user control

<Canvas x:Name="DesignerCanvas"
    ClipToBounds="True"
    SnapsToDevicePixels="True">
   <Gr:BareNode Canvas.Left="168" Canvas.Top="213"/>
</Canvas>

Take the Canvas.Left="168" Canvas.Top="213" part out of the ContentControl declaration of inside the user control.

Mike Two
but i also want the second scenario to work.
DotDot
To get the Left and Top properties, you use two static methods on the Canvas class - Canvas.GetLeft and Canvas.GetTop. Look them up on MSDN.
Boyan
A: 

Absolute or relative point? View point from Object or Canvas?

Do you convert value to Double Type in code?

hope it work...

Bobo