开发者

Textbox lag with a lot of data? (Silverlight 4)

I have a textbox bound to a string in my ViewModel via TwoWay binding that often contains hundreds of lines if not more. When the textbox contains a lot of text, input lag can become apparent when entering text.

So, I'm now trying to track the source of this performance hit and I'm wondering if it could be a limitation of the control itself.

Any thoughts?

Thanks!

Edit:

In my tests I have 800 lines of 211 characters each when I begin to see noticable lag. And the more I add text, the more it lags.

Here's some code:

<TextBox x:Name="rightTextBox" Text="{Binding Source={StaticResource ViewModel}, Path=Text, Mode=TwoWay}"
    AcceptsReturn="True" />

And my textbox is bound to this string:

private string text;
public string Text
{
    get
    {
        return this.text;
    }
    set
    {
        if (this.text != value)
        {
            this.text= value;
            NotifyPropertyChanged("Text");
        }
     }
 }

 public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(string propertyName)
    {
        if (PropertyCha开发者_运维知识库nged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }


So basically you asking the TextBox (which is designed to do things like "Please enter your first name") to handle 300KB worth of text and now your seeing some lag. Hmmm... Have you tried creating an empty Silverlight application containing a single TextBox, assigning that amount of text directly to its Text property and then start editing. Do you stil see lag? If so then it sounds like you're pushing the limits of the ability of text box.

I don't know of a serious alternative perhaps something Third-party might help. Its possible that the RichTextBox may not suffer the same problem since its clearly designed for that sort of text editing. However its not easy to bind to and handles a strange dialect of Xaml rather than straight text.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜