This is a migrated thread and some comments may be shown as answers.

Positioning controls in Code

1 Answer 61 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lindsay Miles
Top achievements
Rank 1
Lindsay Miles asked on 20 May 2010, 09:31 PM
Hello,

if we can position controls (buttons in this case) on a canvas using the canvas.top and canvas.left in the xaml for the given button, how can be position buttons dynamically added to a canvas at run-time? 

Something like:

Canvas cvs = new Canvas;
RadButton btn = new RadButton
{
Tag = "btnONE", Width = 32, Height = 32, Content = "ONE"
}
cvs.Children.Add(btn);

Lets say I have 10 of these (obviously named/tagged differently) in a loop...the buttons should be 5 rows of 2 in the order they were added - ie: left, right, left, right for 5 rows...

How can I position each button? What I'm getting in my code is 10 btns on top of each other.

In xaml I have canvas.top="0" canvas.left="0"
then in next btn canvas.top="0" canvas.left="32"
then in next btn canvas.top="32" canvas.left="0"
then in next btn canvas.top="32" canvas.left="32"

etc etc etc.

Make sense?

Thanks

1 Answer, 1 is accepted

Sort by
0
Lindsay Miles
Top achievements
Rank 1
answered on 21 May 2010, 02:46 PM
Issue Solved.

Added a StackPanel to RadPane then various Grids and Canvases in the xaml.
In my C# code, added required rows and set col width and row height etc etc.
Built the buttons as before and added to relevant Grid or Canvas.

All works and looks good.

Tags
General Discussions
Asked by
Lindsay Miles
Top achievements
Rank 1
Answers by
Lindsay Miles
Top achievements
Rank 1
Share this question
or