none
How to force the update of actual* measure properties RRS feed

  • Question

  • Hi,

    I have a Grid with borders inside.

    I made this, expecting that, after defininf a width and height for the grid, it will propagate to is children their width and height values, because their are in auto.

    I did the folowing:

                    Grid g = s.Layout; // s contains a Grid with no width and height defined, only borders inside
                    g.Width = 1024;
                    g.Height = 768;              

                    foreach (object obj in g.Children)
                    {
                        Border b = obj as Border;

                        if (b != null)
                        {
                            b.ActualWidth.ToString());
               
                        }
                    }

    But, the output of b.ActualWdth is 3... i have tried things like g.InvalidateVisual, but nothing, it continues to be 3.

    How can i force this to update?

    Thx,

    Nuno
    Friday, September 21, 2007 2:16 PM

All replies

  • Make sure the borders contained within the grid do not have any margins set on them (often margins get set by default, especially if you're laying it out in a designer like Blend).

     

    Also, ensure that the VerticalAlignment and HorizontalAlignment of the borders are all set to "Stretch".

    Friday, September 21, 2007 5:22 PM
  • Hi,

     

    I don't have margins on the borders.

     

    Here is an example:

     

     

    <Grid

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Width="150" Height="112.5">

    <Grid.Background>

    <SolidColorBrush Color="White"/>

    </Grid.Background>

    <Grid.ColumnDefinitions>

    <ColumnDefinition Width="0.8*"/>

    <ColumnDefinition Width="0.2*"/>

    </Grid.ColumnDefinitions>

    <Border x:Name="_1" Grid.Column="0" BorderBrush="Black" Background="White" BorderThickness="2,2,1,2" />

    <Border x:Name="_2" Grid.Column="1" BorderBrush="Black" Background="White" BorderThickness="1,2,2,2" />

    </Grid>

     

     

    Nuno

    Monday, September 24, 2007 2:15 PM