wpf 在 vi​​sta / xp 上随机突出显示文本

发布于 2024-11-07 07:20:24 字数 1852 浏览 0 评论 0原文

此问题仅发生在 vista 和 xp 上。发生的情况是,如果有一个文本框包含大量文本并且部分超出屏幕,并且您单击它,wpf 会将其滚动到视图中并在执行此操作时突出显示文本。在 Windows 7 中,它不会将其滚动到视图中。我正在使用 .net 4 并尝试清除文本框接收的焦点、键盘焦点和鼠标捕获事件上的选择,但滚动似乎发生在这些事件之后。我提供了一些我正在谈论的内容的屏幕截图以及演示该问题的测试应用程序。

在单击任何内容之前,在下一个屏幕截图中,我所做的就是单击第 6 行 Before

单击第 6 行后,您可以看到所有内容都突出显示,因为它将文本框滚动到视图中。 after

重现:

/// <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
Before

After clicking on line 6 you can see everything is highlighted as it scrolled the textbox into view.
after

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别靠近我心 2024-11-14 07:20:24

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文