kemarofangs
Topic Author
Posts: 32
Joined: 13 Jun 2014, 21:30

Issue With Determining UIElement Actual Size

22 Jul 2016, 04:05

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
<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>
Breakpointing reveals that the actual size is always zero even after its been drawn on the screen.
Code behind
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();
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: Issue With Determining UIElement Actual Size

22 Jul 2016, 16:51

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.
 
kemarofangs
Topic Author
Posts: 32
Joined: 13 Jun 2014, 21:30

Re: Issue With Determining UIElement Actual Size

22 Jul 2016, 22:18

Thank you again. Changing to grid fixes my issue.
Last edited by kemarofangs on 03 Aug 2016, 07:17, edited 1 time in total.
 
User avatar
jsantos
Site Admin
Posts: 2906
Joined: 20 Jan 2012, 17:18
Contact:

Re: Issue With Determining UIElement Actual Size

23 Jul 2016, 11:36

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.
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.

Who is online

Users browsing this forum: No registered users and 1 guest