Maddy123
Topic Author
Posts: 11
Joined: 23 Oct 2013, 23:19

Getting position of grid control

23 Oct 2013, 23:29

I have created a xaml file with multiple grids(grids can resize) in it. I am trying to figure out a way to get position of those individual grids. For doing so, when I am accessing actual height and width of a grid it returns 0 or 1. Why am I getting wrong values and is there any work around to get position of grid in layout?
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: Getting position of grid control

24 Oct 2013, 12:13

ActualWidth and ActualHeihgt properties should give you the correct size of any element that has been processed during layout.

To get the position you should use PointToScreen() or TransformToAncestor() functions depending relative to what you want that position.

Could you please post the xaml and code you are using to obtain the size and position?
 
Maddy123
Topic Author
Posts: 11
Joined: 23 Oct 2013, 23:19

Re: Getting position of grid control

24 Oct 2013, 17:53

Actually I have two grid in window (on top of each other, dividing the window vertically in half). I am getting height of entire window and bottom grid both as 1 and also width of grid as 0.

I tried all the suggestions you mentioned above but still getting wrong result. Any pointers?
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: Getting position of grid control

24 Oct 2013, 18:37

Please post here the xaml that you are using so I can check the layout of your design.

When are you querying the size? Remember that ActualWidth and ActualHeight are setted after element gets measured and arranged.
 
Maddy123
Topic Author
Posts: 11
Joined: 23 Oct 2013, 23:19

Re: Getting position of grid control

25 Oct 2013, 00:35

Xaml code is :
<Grid x:Name="LayoutRoot" Margin="0,0,0,-1">
	<Grid.ColumnDefinitions>
		<ColumnDefinition Width="0.75*"/>
		<ColumnDefinition Width="0.25*"/>
	</Grid.ColumnDefinitions>
	<Grid x:Name="OgreMasterSlaveView" Margin="0"/>
	<Grid x:Name="OgreSingleView" Margin="0" Grid.ColumnSpan="2"/>
	<Grid x:Name="GridViewLayout" Grid.Column="1" Margin="0" IsHitTestVisible="True">
		<Grid.RowDefinitions>
			<RowDefinition Height="0.5*"/>
			<RowDefinition Height="0.5*"/>
		</Grid.RowDefinitions>
		<Canvas x:Name="OgreSlaveView" Margin="0"/>
		<Grid x:Name="OgreMasterView" Margin="0" Grid.Row="1"/>
	</Grid>
</Grid>
Code:
Math::Matrix4f m = mMasterView->TransformToVisual(_root);

Math::Vector4f v1(0,0,0,1) ; 
Math::Vector4f v2(0,1,0,1);
Math::Vector4f v3(1,1,0,1);
Math::Vector4f v4(1,0,0,1);

auto top_left = v1 * m; 
auto bottom_left = v2 * m; 
auto bottom_right = v3 * m; 
auto top_right = v4 * m;
 
User avatar
sfernandez
Site Admin
Posts: 2997
Joined: 22 Dec 2011, 19:20

Re: Getting position of grid control

25 Oct 2013, 02:48

Before you can query for the size or position of any UI element you have to be sure that IRenderer::SetSize() was called with the appropriate dimensions, and IRenderer::Update() was called to layout (measure and arrange) UI elements.

If I execute the following code after the window is measured and arranged, I get the correct size and absolute position:
NsFloat32 width = mMasterView->GetActualWidth();
NsFloat32 height = mMasterView->GetActualHeight();
Drawing::Point pos = mMasterView->PointToScreen(Drawing::Point::Zero());

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests