wpf 在 vista / xp 上随机突出显示文本
此问题仅发生在 vista 和 xp 上。发生的情况是,如果有一个文本框包含大量文本并且部分超出屏幕,并且您单击它,wpf 会将其滚动到视图中并在执行此操作时突出显示文本。在 Windows 7 中,它不会将其滚动到视图中。我正在使用 .net 4 并尝试清除文本框接收的焦点、键盘焦点和鼠标捕获事件上的选择,但滚动似乎发生在这些事件之后。我提供了一些我正在谈论的内容的屏幕截图以及演示该问题的测试应用程序。
在单击任何内容之前,在下一个屏幕截图中,我所做的就是单击第 6 行
单击第 6 行后,您可以看到所有内容都突出显示,因为它将文本框滚动到视图中。
重现:
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
for (int i = 1; i < 1000; i++)
{
textBox3.AppendText(string.Format("line {0}\r\n", i));
}
}
}
<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="350" Width="525" MaxHeight="350" MaxWidth="525">
<Grid>
<ScrollViewer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="this is some text"></TextBox>
<TextBox Grid.Row="1" Text="this is some text"></TextBox>
<TextBox Grid.Row="2" ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto" AcceptsReturn="True"
x:Name="textBox3"></TextBox>
</Grid>
</ScrollViewer>
</Grid>
</Window>
This issue only happens on vista and xp. What is happening is if there is a textbox that has a lot of text and is partially off the screen and you click in it, wpf will scroll it into view and highlight text while it does this. In windows 7 it won't scroll it into view. I am using .net 4 and have tried clearing the selection on the textbox's received focus, got keyboard focus, and mouse capture events, but the scroll seems to take place after those. I have included some screen shots of what I am talking about as well as a test app that demonstrates the problem.
Before clicking on anything, In the next screen shot all I have done was click on line 6
After clicking on line 6 you can see everything is highlighted as it scrolled the textbox into view.
repro:
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
for (int i = 1; i < 1000; i++)
{
textBox3.AppendText(string.Format("line {0}\r\n", i));
}
}
}
<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="350" Width="525" MaxHeight="350" MaxWidth="525">
<Grid>
<ScrollViewer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"></RowDefinition>
<RowDefinition Height="auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="this is some text"></TextBox>
<TextBox Grid.Row="1" Text="this is some text"></TextBox>
<TextBox Grid.Row="2" ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto" AcceptsReturn="True"
x:Name="textBox3"></TextBox>
</Grid>
</ScrollViewer>
</Grid>
</Window>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Microsoft 发现这是 .net 3.5 中的一个已知问题,并在 .net 4.0 中修复。他们没有解决办法。
Turns out from Microsoft that this is a known issue in .net 3.5 and they fixed in .net 4.0. they did not have a work around.