Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Get ActualWidth and ActualHeight in constructor RSS

2 replies

Last post Oct 14, 2008 07:43 AM by forci

(0)
  • forci

    forci

    Member

    351 Points

    275 Posts

    Get ActualWidth and ActualHeight in constructor

    Oct 13, 2008 08:38 AM | LINK

    I have this xaml:

    <UserControl x:Class="ClientLibrary1.Controls.Land1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
        <Grid x:Name="gLand" Background="Yellow">
           
        </Grid>
    </UserControl>

     Now i want to get the actualWidth and actualHeight of Grid fLand in constructor of object Land1. The actual width/height is in constructor 0, but if i add some MouseLeftButtonUp on gLand, and there read actual width/height, the values are correct.

    So i want to get this two values automatic at some time after create. How to do this. I don't want to add some timer and then check values. There must be a better idea.
    I believe, that immediatelly after creating the UserControl the grid isn't stretch yet, so the actual width/height is 0. Then some painting is done, and after that i can get dimension.

     Any idea?

    Make love not war.
  • Sergey.Lutay

    Sergey.Lutay

    Star

    13559 Points

    2381 Posts

    Re: Get ActualWidth and ActualHeight in constructor

    Oct 13, 2008 10:04 AM | LINK

    Hi,

    Try to use LayoutUpdated event of UserControl class if you need to know actual width/height periodically.

    Silverlight 2

    (If I answered the question, please click on "mark as answer".)

    Twitter

    Sincerely,
    Sergii Lutai

    MCT, MCPD, Head of Dev. Dept at DCT
  • forci

    forci

    Member

    351 Points

    275 Posts

    Re: Re: Get ActualWidth and ActualHeight in constructor

    Oct 14, 2008 07:43 AM | LINK

     Thanks

    Make love not war.