tags:

views:

30

answers:

2

I have a WrapPanel placed in a grid and fill it dynamically with ToggleButtons.
The height of the row, where the wrappanel is located in, is calculated based on the number of ToggleButtons in the WrapPanel component.
When I load my screen the items in the wrappanel aren't layouted correctly. However when I resize my form the items are shown correctly.
Is there a method where you can force to relayout the items like it does when you resize your form ? Below you can see my WPF code:

<Grid x:Name="grdScreen">
    <Grid.RowDefinitions>
        <RowDefinition x:Name="rdToolBar" Height="21" />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150" />
            <ColumnDefinition Width="150" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <ToggleButton Grid.Column="0" Name="btnlegende" Margin="1,1,11,1" Click="btnlegende_Click" />
        <Button Grid.Column="1" Name="btnlayout" Margin="1" Click="btnlayout_Click" />
        <WrapPanel x:Name="pnlHeader" Grid.Column="2" />
    </Grid>
...
</Grid>
A: 

try this.UpdateLayout();

Ragunathan
add this code after the controls are added dynamically.
Ragunathan
I tried it already.Even pnlHeader.upateLayout().It doesn't work.
Just try putting the Wrap panel code seperately in a usercontrol, i mean not inside the Grid.
Ragunathan
I replaced the grid by a StackPanel and it seems to work now.
A: 

You can call InvalidateArrange() or InvalidateMeasure() to force WPF to redo the appropriate layout phase.

Quartermeister