views:

97

answers:

1

Hello,

I'm trying to display a game desk and info panel right next to the game desk and I need to calculate minimal width of the info panel in order to display the game desk properly.

This is my XAML code:

<StackPanel Orientation="Horizontal">
    <Rectangle Width="Auto" Height="Auto" Name="gamedeskRect" Style="{DynamicResource GameDesk}" />
    <StackPanel Name="infoPanel" Width="Auto" HorizontalAlignment="Right" Height="Auto"  VerticalAlignment="Center" Margin="10,0,0,0">
    <!-- a few textblocks in a grid here -->
    </StackPanel>
</StackPanel>

And the problem is that when I'm resizing the window a part of the right panel may be cropped which is what I don't want.

+1  A: 

The problem is that you are using the wrong outer panel. It is allowing the first Rectangle to take as much space as it wants, instead of the remaining space. If you switch to a DockPanel, this should solve your issue (although you will need to reorganize your contents a bit to support the LastChildFill):

<DockPanel LastChildFill="True">
    <StackPanel Name="infoPanel" DockPanel.Dock="Right" VerticalAlignment="Center" Margin="10,0,0,0">
    <!-- a few textblocks in a grid here -->
    </StackPanel>
    <Rectangle Width="Auto" Height="Auto" Name="gamedeskRect" Style="{DynamicResource GameDesk}" />
</DockPanel>
Abe Heidebrecht