简体   繁体   English

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

[英]Strange TextBox behavior in Windows 8.1 and windows 10

The following code works like expected in Windows 7: 以下代码的工作方式与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>

The same code running under Win8.1 or Win10 shows the TextBox with its vertical scrollbar centered vertically within a larger TextBox area. 在Win8.1或Win10下运行的相同代码显示了TextBox,其垂直滚动条在较大的TextBox区域内垂直居中。

It seems to be a WPF layout problem. 这似乎是WPF布局问题。 The code was developed in VS2013, .net 4.5. 该代码是在VS2013.net 4.5中开发的。 All tested windows systems are x64. 所有经过测试的Windows系统均为x64。 Any ideas to make this simple app running with same results in win7 ... win10? 有什么想法可以使这个简单的应用程序在win7 ... win10中以相同的结果运行?

Remove the line 删除线

MaxLines="6" 

it is causing your Textbox to be limited in height and appear vertically centered in Window 这会导致您的Textbox高度受到限制,并在“ Window垂直居中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM