我做了一個實驗,幫助我在FlowDocumentScrollViewer,RichTextBox和TextBlock中選擇我喜歡的控件。我發現FlowDocumentScrollViewer是最好的。
在每個窗口中,我有兩個相同類型的控件:FlowDocumentScrollViewer,RichTextBox或TextBlock。我做了三個這樣的窗口,因爲MainWindow有三個按鈕。 ![enter image description here](https://i.stack.imgur.com/n13J2.png)
private void prepareButton_Click(object sender, RoutedEventArgs e)
{
document1 = HelperClass.GetDocument();
document2 = HelperClass.GetDocument();
}
private void loadButton_Click_1(object sender, RoutedEventArgs e)
{
Stopwatch watch = new Stopwatch();
watch.Start();
viewer1.Document = document1;
viewer2.Document = document2;
this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded,
new Action(() =>
{
watch.Stop();
MessageBox.Show("Took " + watch.ElapsedMilliseconds + " ms",Title);
}));
}
凡viewer1和viewer2可以FlowDocumentScrollViewer或RichTextBox的。 對於TextBlock的,我用
private void prepareButton_Click(object sender, RoutedEventArgs e)
{
inlines1 = HelperClass.GetInlines();
inlines2 = HelperClass.GetInlines();
}
private void loadButton_Click_1(object sender, RoutedEventArgs e)
{
Stopwatch watch = new Stopwatch();
watch.Start();
viewer1.Inlines.AddRange(inlines1);
viewer2.Inlines.AddRange(inlines2);
this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded,
new Action(() =>
{
watch.Stop();
MessageBox.Show("Took " + watch.ElapsedMilliseconds + " ms");
}));
}
試驗表明FlowDocumentScrollViewer有三間最佳性能:
FlowDocumentScrollViewer RichTextBox TextBlock
Working set 65400 67252 82124
Loading Time 1045 1414 45119
您應該能夠使用'IsReadOnly'財產上的大多數控件。 – 2012-07-13 01:56:37
@DougRamsey然而,內建的編輯支持需要一些資源;我想找到一個輕量級的,就像我在我的問題中所說的那樣。 – Gqqnbig 2012-07-13 01:58:35
如果你想要輕量級的,WPF應用程序可以得到一些大(當然相對來說)。也許你想考慮像MFC應用程序這樣的應用程序,它具有最小的依賴關係,並且通常使用更少的內存。只是一個想法。 – 2012-07-13 02:20:27