How to place UserControl in parent canvas

I want to place this UserControl on Canvas.Left = "168", Canvas.Top = "213".

However, the control appears in the corner. What should I do?

If I put the values ​​at the point of use for this class, the values ​​are returned as NaN In this case, how can I get the left and top values ​​correct?

Using:

<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">

<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>

      

+1


source to share


1 answer


I'm not sure if you've tried this or not, but looking at the XAML it seems that you are trying to set the position of the custom control inside the custom control. It won't work. You need to put it when you are using the custom 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 from the ContentControl declaration inside the custom control.

+4


source







All Articles