【发布时间】:2015-03-18 02:42:48
【问题描述】:
如果 wpf 应用程序已将窗口的 UseLayoutRounding 设置为 true,则 gridsplitter 将不再适用于某些窗口宽度(它将卡在其原始位置),如下例所示。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="200" Width="401"
UseLayoutRounding="True">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0">
long string that does not fit within the textblock - long string that does not fit within the textblock
</TextBlock>
<GridSplitter Grid.Column="1" HorizontalAlignment="Center" Width="50" Background="LightBlue" />
<TextBlock Grid.Column="2">
long string that does not fit within the textblock - long string that does not fit within the textblock
</TextBlock>
</Grid>
</Window>
请注意,对于生成错误的示例,窗口宽度必须为 401,文本框中的文本必须比文本框长,并且 UseLayoutRounding 必须为 true。
任何知道如何避免这种情况或有任何解决方法的人?我不想将 UseLayoutRounding 设置为 false,因为它会在我的应用程序中导致呈现伪影。
编辑: 对于其他有同样问题的人,我发现这个用户制作的组件可以解决这个问题:http://blog.onedevjob.com/2011/12/11/fixing-wpf-gridsplitter/ 不过如果可以使用默认的 wpf 组件来解决它仍然会很好。
【问题讨论】:
标签: wpf