开发者

How to find out minimal render size of a visual in WPF?

开发者 https://www.devze.com 2022-12-26 08:41 出处:网络
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.

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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号