1

I want an element or a control to show readyonly, colorful, selectable, scrollable text which is a kind of log in my application. I don't know whether it is fixed document or flow document.

The RichText may be the seeming choice, but it originally supports editing. I believe even I set readonly=true, the build-in editing support takes some resources. I want to find a lighter-weight one.

Perhaps the FlowDocumentScrollViewer? It is readonly and do not show tool bar by default. Even I turn IsToolBarVisible on, the tool bar is just a small control.

The Block came into my mind. Although it may be the lightest control, I cannot select the text in it without other effort.

Maybe other choices exist? What's your opinions?

4

2 に答える 2

1

I made an experiment to help me choose my preferable control among FlowDocumentScrollViewer, RichTextBox, and TextBlock. I find FlowDocumentScrollViewer is the best.

In each window I have two controls of same type: FlowDocumentScrollViewer, RichTextBox, or TextBlock. And I made three such windows, as the MainWindow has three buttons. enter image description here

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);
                  }));
}

Where viewer1 and viewer2 can be FlowDocumentScrollViewer or RichTextBox. For TextBlock, I use

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");
                  }));
}

The test indicates FlowDocumentScrollViewer has best performance among the three:

             FlowDocumentScrollViewer   RichTextBox    TextBlock
Working set      65400                    67252          82124
Loading Time      1045                    1414           45119
于 2012-07-13T06:20:22.127 に答える
0

I'm not sure what type of resources you think are being taken up by "editing" functionality. The ability to select text goes hand in hand with ability to edit text.

If you want one, you'll have to put up with the other. Luckilly, setting IsReadOnly to "True" will satisfy your functional requirements.

If your application machine is capable of running the .NET Framework with WPF, I wouldn't worry about tiny amounts of resources which may (or may not) be consumed by the ability to edit simple text.

于 2012-07-13T02:10:01.340 に答える