以下 XAML 会在文本框周围生成一个具有奇怪行为的窗口:
<Window x:Class="WpfSandbox.CuriousExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="CuriousExample" Height="300" Width="300">
<DockPanel Margin="15">
<TextBox BorderThickness="1" BorderBrush="#FF000000"></TextBox>
</DockPanel>
</Window>
至少在我有限的测试期间,会发生什么情况是文本框呈现出带有嵌入边框的图案(上/左为黑色,右/下为灰色)。但是,当您调整到除原始位置以外的任何位置时,整个文本框边框将变为黑色。每当您将窗口返回到表单首次加载时的屏幕像素的确切数量时,它就会再次插入。
我猜这不是像素捕捉,因为我可以使用以下代码轻松纠正问题:
<Window x:Class="WpfSandbox.CuriousExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="CuriousExample" Height="300" Width="300">
<DockPanel Margin="15">
<Border BorderThickness="1" BorderBrush="#FF000000">
<TextBox BorderThickness="0" ></TextBox>
</Border>
</DockPanel>
</Window>
有人愿意冒险解释我所看到的吗?或者这一切都在我的脑海里?
就像我说的,上述解决方法可以解决这个问题——只是想了解这里发生了什么。
谢谢,
-斯科特
最佳答案
您可以强制应用程序使用 vista 主题 (aero)
打开您的 app.xaml 并输入以下内容:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component/themes/aero.normalcolor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
不要忘记将 PresentationFramework.Aero 引用放入您的项目中。
有了这个,您将像在 Vista 中一样在 XP 中看到您的应用程序。
关于WPF 文本框和边框 - 奇怪的调整大小行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/997760/