M
M
msis2017-10-16 18:51:59
WPF
msis, 2017-10-16 18:51:59

Tool in wpf to quickly display large text information?

Good afternoon. Tell me, please, with the help of which you can display large text in wpf quickly? and so that it was possible to format the necessary parts of this text in advance (from the code). I tried to output heaps of small text blocks to the canvas (with formatting the necessary ones), but it took a lot of time and memory. I tried one textblock with a bunch of Runners, too long. Tried RichTextBox - It's quite slow.. Tried canvas with FormattedText added to it (quick, but no required formatting, I had to draw rectangles with absolute positioning in a separate layer (as if the text had a background), so everything floated). I tried to do it on MVC (what if), but it's also slow there. What other tools can you try?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Yudakov, 2017-10-20
@msis

Out of boredom, I drew a simpler solution - a custom panel that displays a grid with cells of a fixed size. Borders, Backgrounds of cells - at your discretion in the CreateCell and BindCell methods.
I tried 1 million x 1 million cells - no brakes. Only what is visible on the screen is displayed.
59e9ec8d02f32162485723.png

<Window x:Class="GridTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:GridTest"
        Title="Square Grid Test" Height="350" Width="525">
    <ScrollViewer CanContentScroll="True" 
                HorizontalScrollBarVisibility="Visible"
                VerticalScrollBarVisibility="Visible">
        <local:SquareGrid x:Name="Grid">
        </local:SquareGrid>
    </ScrollViewer>
</Window>

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace GridTest
{
    public partial class MainWindow : Window, SquareGrid.ICellGenerator
    {
        public MainWindow()
        {
            InitializeComponent();

            Grid.RowCount = 1000;
            Grid.ColumnCount = 1000;
            Grid.CellWidth = 36;
            Grid.CellGenerator = this;
        }

        public UIElement CreateCell()
        {
            return new Border
            {
                Child = new TextBlock
                {
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center,
                    FontSize = 10
                },
                BorderBrush = Brushes.LightGray,
                BorderThickness = new Thickness(0, 0, 1, 1)
            };
        }

        public void BindCell(UIElement view, int x, int y)
        {
            var border = (Border)view;
            var textBlock = (TextBlock)border.Child;
            textBlock.Text = "" + x + ":" + y;
        }
    }
}

public sealed class SquareGrid : Panel, IScrollInfo
{
    // Подробности сюда не влезли,
    // см. SquareGrid.cs
}

SquareGrid.cs Entire
project: SquareGrid.zip

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question