【发布时间】:2011-09-29 12:27:44
【问题描述】:
我有一个文本框通过 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));
}
【问题讨论】:
-
您是否将 UpdateSourceTrigger 更改为 PropertyChanged ?如果是,那么这可能是原因
-
不。我用 XAML 更新了我的帖子。
-
@hyp:在 Silverlight 中,您只能选择
Default或Explicit。 TextBox 默认是在焦点离开控件时更新。 Tigel:你可以通过删除 TwoWay 来确定绑定是否是问题的一部分,看看会发生什么,但我怀疑它会改变什么。 -
@AnthonyWJones 是的,我刚刚尝试使用 OneWay 绑定,但它仍然滞后:(
-
你能更精确地量化事物吗?在您发现可见滞后的测试中究竟有多少行和多少个字符?
标签: c# silverlight user-interface silverlight-4.0