Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Position of UIElement
4 replies. Latest Post by jeetumaker on November 7, 2009.
(0)
v_georgiev
Member
4 points
13 Posts
11-06-2009 2:44 AM |
In Windows Forms, when I set the position of an UIElement I do it that way:
UIElement.Location = new Point(X, Y); // then I get it with UIElement.Location.X UIElement.Location.Y
//
What is this Margin about?
Pravinku...
Contributor
4300 points
708 Posts
11-06-2009 2:56 AM |
Hi,
You can set the position of the controls within canvas using
Canvas.SetLeft(object,value);
Canvas.SetTop(object,value);
Check the below articals as well-
http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-2-using-layout-management.aspx
http://msdn.microsoft.com/en-us/library/cc189087(VS.95).aspx
Thanks,
Pravin
"Please mark as answered, if this answers your question"
amyo
3630 points
495 Posts
11-06-2009 3:05 AM |
You can use the SetValue method to set the Canvas Left (X) and Top(Y) property
Sample:
<Canvas x:Name="LayoutRoot" Background="White"> <Canvas x:Name="myCanvas"></Canvas> </Canvas>
//X myCanvas.SetValue(Canvas.LeftProperty, 20); //Y myCanvas.SetValue(Canvas.TopProperty, 20); //Above X, Y of myCanvas relative to LayoutRoot
11-07-2009 3:47 AM |
And how can I get these values in double, because GetValue gives me object?
jeetumaker
525 points
92 Posts
11-07-2009 5:11 AM |
to get values in double either use the Convert.ToDouble or the type cast - for eg: In C# you can use :
double x = (double) objectVariable