I am having a performance problem binding a large string to a a TextBox in WPF.
In the view I am binding a TextBox’s Text property to the view model’s Output property which is a StringBuilder.
View:
<TextBox Text="{Binding Output, Mode=OneWay}" IsReadOnly="True"/>
ViewModel:
public StringBuilder Output
{
get { return _output; }
}
As the text in the StringBuilder gets larger the performance of the binding degrades.
What’s a better way to do this using MVVM?
One possible way of getting around delays in databinding is to use asynchrnous binding. You can do this by setting IsAsync property of your binding object :
This will of course not solve the problem of the binding taking a long time but will stop the UI from freezing whilst it does the binding.
You can also use priority binding to show a cut down version of the text (which is quick to load) whilst the larger text item is loaded. Priority binding is described on msdn – >http://msdn.microsoft.com/en-us/library/ms753174.aspx.