2010-08-12 61 views
4

我有一个两行加上网格分离器的网格。我希望默认情况下顶行的高度尽可能小(在这种情况下,按钮的高度)底行应扩大以占据网格中的剩余空间。我希望网格分离器允许用户根据需要更改大小。如何使wpf行缩小以适合内容

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition /> 
     <RowDefinition Height="5" /> 
     <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 

    <Button Grid.Row="0" Content="A little old button" VerticalAlignment="Center" /> 
    <GridSplitter Grid.Row="1" Background="Black" HorizontalAlignment="Stretch" /> 
    <TextBlock Grid.Row="2" TextWrapping="Wrap"> 
     Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum. 
    </TextBlock> 
</Grid> 

我该如何设置xaml?

回答

10
<RowDefinition Height="Auto" /> 

应该这样做。

+1

是否有任何其他考虑因素需要考虑。在我的情况下,使用* Auto *可以实现更多的传播。我试着玩* MinHeight *和* MaxHeight *,但是没有真正做到。我有一个有堆叠面板的网格,每个堆叠面板都有一个标签和一个组合框。 (是的,我一直在为它们中的每一个尝试样式,包括行定义。) – 2015-01-04 11:39:19

+0

@KonradViltersten您是否已经尝试了',以便必须自动展开的行。 – rraallvv 2018-01-04 14:49:32

相关问题