Getting position of grid control
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?
-
-
sfernandez
Site Admin
- Posts: 3197
- Joined:
Re: Getting position of grid control
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?
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?
Re: Getting position of grid control
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?
I tried all the suggestions you mentioned above but still getting wrong result. Any pointers?
-
-
sfernandez
Site Admin
- Posts: 3197
- Joined:
Re: Getting position of grid control
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.
When are you querying the size? Remember that ActualWidth and ActualHeight are setted after element gets measured and arranged.
Re: Getting position of grid control
Xaml code is :
Code:
Code: Select all
<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: Select all
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;
-
-
sfernandez
Site Admin
- Posts: 3197
- Joined:
Re: Getting position of grid control
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:
If I execute the following code after the window is measured and arranged, I get the correct size and absolute position:
Code: Select all
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] and 2 guests