使用以下代码,我希望最终得到两个具有相同宽度的ListBox,它们都被放置在两个Width="*"的ColumnDefinition中。
但实际上,它们的大小似乎是由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中完成,以防有影响。