Windows 8.1和Windows 10中的奇怪TextBox行为

时间:2015-08-28 12:28:18

标签: c# wpf

以下代码与Windows 7中预期的一样:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="WpfApplication2.MainWindow"
    Title="MainWindow"
    Height="Auto"
    Width="500"
    ResizeMode="NoResize"
    WindowStyle="SingleBorderWindow" 
    SizeToContent="Height" 
    WindowStartupLocation="CenterScreen">
<Grid>
    <TextBox IsReadOnly="True"
             MinLines="6"
             MaxLines="6" 
             TextWrapping="Wrap"
             VerticalScrollBarVisibility="Visible"
             Text="test &#10;test &#10;test &#10;test &#10;test &#10;test &#10;test &#10;test &#10;test &#10;"/>
</Grid>

在Win8.1或Win10下运行的相同代码显示TextBox,其垂直滚动条在较大的TextBox区域内垂直居中。

这似乎是一个WPF布局问题。该代码是在VS2013,.net 4.5中开发的。所有经过测试的Windows系统都是x64。 任何使这个简单的应用程序以相同的结果运行的想法都会在win7 ... win10?

1 个答案:

答案 0 :(得分:1)

删除行

MaxLines="6" 

导致Textbox的身高受到限制,并在Window

中垂直居中显示