Hasan Zubairi
Hasan Zubairi

Reputation: 1183

Position controls in dynamic canvas

In my application I am using a canvas which is dynamically generated at runtime. I am placing a textblock on the canvas but it is showing at top left corner of the canvas. How can I change its position. I have search and everyone is showing myCanvas.SetLeft(myTextBlock,10); but I could not find this command in the dropdown list.

Is there any other method to achieve this?

Upvotes: 0

Views: 1053

Answers (1)

Leslie Davies
Leslie Davies

Reputation: 4112

Try just

myCanvas.Children.Add(myTextBlock);

Canvas.SetLeft(myTextBlock,10);

This will add your textblock to the children collection of myCanvas and then the Canvas class can allow myCanvas to control the left properties of all its children.

This is an example of an attached property.

Upvotes: 1

Related Questions