How to specify parent properties of a control in code behind C# #18050
-
How can I add parent properties to a control in code behind C#? I'm not sure 'parent properties' is the correct terminology. So first let me give an example of assigning parent properties in axaml: <Canvas>
<Rectangle
Fill="Blue" Height="100" Width="100"
Canvas.Left="50" Canvas.Top="20"/>
</Canvas> But I want to do it in code behind. So the axaml becomes a mere stub, like this <Canvas x:Name="Canvas" /> And this is as far as I have got with the C#: Canvas.Children.Add(new Rectangle {
Fill = Brushes.Blue,
Height=100,
Width=100,
}); So, in this example, how can I specify |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is not about parent, but the AttachedProperty system in xaml. Specific to this question, you can simply call Canvas.SetTop( yourRectangle, 10); Notice that this is a static method, the Canvas here is class name, not instance name. |
Beta Was this translation helpful? Give feedback.
This is not about parent, but the AttachedProperty system in xaml.
Specific to this question, you can simply call
Notice that this is a static method, the Canvas here is class name, not instance name.