我在http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5c7f5cdf-4351-4969-990f-29ce9ec84b87/上提出了一个问题,但仍然缺乏关于奇怪行为的好解释。
运行以下XAML代码,可以看到列0中的TextBlock宽度大于100,即使已将该列设置为宽度100。我认为这种奇怪的现象可能与它被包含在ScrollViewer中有关,但我不知道原因。如果在列上设置MaxWidth,则可以正常工作,但设置Width则不行。
以下是需要回答的问题:
1. 为什么列0的宽度没有被遵守?
2. 当您删除滚动视图时,列大小调整的行为为什么会不同?
非常感谢任何解释!这对我来说真是个难题。
运行以下XAML代码,可以看到列0中的TextBlock宽度大于100,即使已将该列设置为宽度100。我认为这种奇怪的现象可能与它被包含在ScrollViewer中有关,但我不知道原因。如果在列上设置MaxWidth,则可以正常工作,但设置Width则不行。
以下是需要回答的问题:
1. 为什么列0的宽度没有被遵守?
2. 当您删除滚动视图时,列大小调整的行为为什么会不同?
非常感谢任何解释!这对我来说真是个难题。
<Window x:Class="WpfApplication2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Width="300">
<ScrollViewer HorizontalScrollBarVisibility="Auto" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock x:Name="textBlock" Text="{Binding ElementName=textBlock, Path=ActualWidth}" />
<TextBlock Text="column 1" Grid.Column="1" />
<TextBlock Grid.Row="1" Grid.ColumnSpan="3" Text="text here that is wider than the first two columns combined" />
</Grid>
</ScrollViewer>
</Window>