文本框有大量数据滞后? (银光4)
我有一个文本框通过 TwoWay 绑定绑定到 ViewModel 中的字符串,该文本框通常包含数百行(如果不是更多)。当文本框包含大量文本时,输入文本时输入滞后会变得明显。
因此,我现在正在尝试跟踪这种性能影响的根源,我想知道这是否可能是控件本身的限制。
有什么想法吗?
谢谢!
编辑:
在我的测试中,当我开始看到明显的滞后时,我有 800 行,每行 211 个字符。添加文本越多,它就越滞后。
这是一些代码:
<TextBox x:Name="rightTextBox" Text="{Binding Source={StaticResource ViewModel}, Path=Text, Mode=TwoWay}"
AcceptsReturn="True" />
我的文本框绑定到这个字符串:
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 (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
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 (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以基本上你要求 TextBox(它的设计目的是做“请输入你的名字”之类的事情)处理 300KB 的文本,现在你看到一些滞后。嗯...您是否尝试过创建一个包含单个 TextBox 的空 Silverlight 应用程序,将一定数量的文本直接分配给其 Text 属性,然后开始编辑。您仍然看到滞后吗?如果是这样,那么听起来您正在突破文本框能力的极限。
我不知道有什么严肃的替代方案,也许第三方可能会有所帮助。
RichTextBox
可能不会遇到同样的问题,因为它显然是为此类文本编辑而设计的。然而,绑定和处理奇怪的 Xaml 方言而不是直接文本并不容易。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.