开发者

wpf randomly highlighting text on vista / xp

开发者 https://www.devze.com 2023-03-06 06:33 出处:网络
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 highligh

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

wpf randomly highlighting text on vista / xp

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

wpf randomly highlighting text on vista / xp

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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消