-
- kemarofangs
- Posts: 32
- Joined:
Issue With Determining UIElement Actual Size
Hey, a simple problem I'm having is grabbing the actual size of a parent container. The child containers may have any number of randomly sized components. In VS this code just works. Is this a bug that exists / was fixed? If there is another way to get the size please let me know. I looked here but the info doesn't seem to help me.
viewtopic.php?f=3&t=537
PS: I've sent in my invoice number in order to get access to the newer noesis build in case this has been fixed since my old version.
XAML
Breakpointing reveals that the actual size is always zero even after its been drawn on the screen.
Code behind
viewtopic.php?f=3&t=537
PS: I've sent in my invoice number in order to get access to the newer noesis build in case this has been fixed since my old version.
XAML
Code: Select all
<Canvas Canvas.Left="0" Canvas.Top="200" x:Name="m_canvas_player1">
<Rectangle Fill="Blue" Width="50" Height="50"/>
<Rectangle Fill="Yellow" Width="5" Height="5" Canvas.Left="22.5" />
</Canvas>
Code behind
Code: Select all
float centerX = m_canvas_player1.GetActualWidth() / 2f;
float centerY = m_canvas_player1.GetActualHeight() / 2f;
m_canvas_player1.UpdateLayout();
Noesis.Size size = m_canvas_player1.GetRenderSize();
-
-
sfernandez
Site Admin
- Posts: 2064
- Joined:
Re: Issue With Determining UIElement Actual Size
Hi,
The layout process in WPF consists in 2 steps: Measure and Arrange. During Measure elements return to its parent the minimum size that is available for measure. This will be the element's DesiredSize. In the next step parent positions children according to some algorithm and usually taking into account children's DesiredSize.
Canvas panel always return 0x0 as DesiredSize in its Measure pass. And Canvas panel arranges its children using Canvas attached properties (Canvas.Left, Canvas.Top, Canvas.Right, Canvas.Bottom) and children's DesiredSize.
Looking at your code it seems that "m_canvas_player1" is inside another Canvas panel. So, in your example, the inner canvas will always have a final size of 0x0. You should provide an explicit size to your inner Canvas, or place it inside another type of container that allows children to fill all the arrange size, like the Grid.
The layout process in WPF consists in 2 steps: Measure and Arrange. During Measure elements return to its parent the minimum size that is available for measure. This will be the element's DesiredSize. In the next step parent positions children according to some algorithm and usually taking into account children's DesiredSize.
Canvas panel always return 0x0 as DesiredSize in its Measure pass. And Canvas panel arranges its children using Canvas attached properties (Canvas.Left, Canvas.Top, Canvas.Right, Canvas.Bottom) and children's DesiredSize.
Looking at your code it seems that "m_canvas_player1" is inside another Canvas panel. So, in your example, the inner canvas will always have a final size of 0x0. You should provide an explicit size to your inner Canvas, or place it inside another type of container that allows children to fill all the arrange size, like the Grid.
-
- kemarofangs
- Posts: 32
- Joined:
Re: Issue With Determining UIElement Actual Size
Thank you again. Changing to grid fixes my issue.
Last edited by kemarofangs on 03 Aug 2016, 07:17, edited 1 time in total.
Re: Issue With Determining UIElement Actual Size
Yes, please, answer our email to solve the issue with the invoice number. The one you sent us doesn't seem to be a valid one.PS: I've sent in my invoice number in order to get access to the newer noesis build in case this has been fixed since my old version.
Who is online
Users browsing this forum: Bing [Bot] and 1 guest