【发布时间】:2012-02-24 09:41:13
【问题描述】:
使用以下代码,我希望以两个具有相同宽度的 ListBox 结束,它们进入两个带有 With="*" 的列定义
看起来大小是由 ListBox 上的文本大小决定的,这没有意义,因为此文本比 ListBox 小得多,因此 TextBlock 有足够的空间来容纳文本。
<Window x:Class="UnderstandSizing.Window5"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window5"
SizeToContent="WidthAndHeight"
ResizeMode="NoResize" >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="Text1longer" Grid.Row="0" Grid.Column="0" x:Name="Test1" />
<TextBlock Text="Text1" Grid.Row="0" Grid.Column="2" />
<ListBox Grid.Row="1" Grid.Column="0" Height="150" />
<ListBox Grid.Row="1" Grid.Column="2" Height="150" />
<TextBlock Grid.Row="2" Grid.ColumnSpan="3" Text="This textblock sets the max width" Width="300" />
</Grid>
</Window>
WPF 自动调整大小功能让我抓狂......有什么想法吗? 谢谢。
编辑:一切都在 VS2008 中完成,以防万一。
【问题讨论】:
标签: .net wpf grid resize sizetocontent