'Textblock Runs Binding perfomance

(Sorry, google Translate)

I'm writing a WPF chat and I'm running into a Textblock.Inlines binding performance issue.

The problem occurs when switching tabs TabControl (actually it's not a TabControl, but just a list on the right with bots and in the middle of the ContentControl). I tried using a TabControl where the tabs are not unloaded, but the problem remains.

When I switch, the interface freezes, especially if there are a lot of messages.

I tried to make Bindind isAsync true for each element, but the list is loaded from top to bottom, I would like it the other way around.

My ChatControl:

<UserControl x:Class="MinecraftBotManager.CustomControls.ChatControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:MinecraftBotManager.CustomControls"
         mc:Ignorable="d"             
         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
         xmlns:assist="clr-namespace:MinecraftBotManager.Asists"
         xmlns:mat="http://materialdesigninxaml.net/winfx/xaml/themes"
         xmlns:models="clr-namespace:MinecraftBotManager.Models"
         xmlns:mcm="clr-namespace:MinecraftLibrary.MinecraftModels;assembly=MinecraftLibrary"
         xmlns:vms="clr-namespace:MinecraftBotManager.ViewModel"
         xmlns:avalon="http://icsharpcode.net/sharpdevelop/avalonedit"
         xmlns:beh="clr-namespace:MinecraftBotManager.Behaviors"
         d:DesignHeight="450" d:DesignWidth="800">
<Grid x:Name="GridChat">        
    <ScrollViewer x:Name="ScrollChat" Height="300" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.ScrollUnit="Pixel" VirtualizingPanel.CacheLength="30" VirtualizingPanel.VirtualizationMode="Recycling"  VerticalScrollBarVisibility="Visible">
        <ItemsControl x:Name="ChatList" ItemsSource="{Binding ChatQueue,IsAsync=True}"                           
                       VerticalAlignment="Bottom" >
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <local:ChatTextBlock/>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>
    </ScrollViewer>

    <Grid Margin="15" HorizontalAlignment="Right" VerticalAlignment="Bottom">
        <Button Visibility="Collapsed" Name="ButtonExpand" Style="{StaticResource MaterialDesignFloatingActionButton}" Width="50" Height="50">
            <Button.Content>
                <mat:PackIcon Height="Auto" Width="Auto" Margin="3" Kind="ExpandMore"/>
            </Button.Content>
        </Button>
        <Grid Visibility="Hidden" x:Name="GridEllipse" HorizontalAlignment="Left" VerticalAlignment="Top">
            <Ellipse Height="20" Width="20" Fill="#FF387CCF"/>
            <TextBlock x:Name="NewMessageCount" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White"/>
        </Grid>
    </Grid>
</Grid>

ChatTextBlock

<UserControl x:Class="MinecraftBotManager.CustomControls.ChatTextBlock"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:MinecraftBotManager.CustomControls"
         mc:Ignorable="d"
         xmlns:converts="clr-namespace:MinecraftBotManager.Converters"
          xmlns:beh="clr-namespace:MinecraftBotManager.Behaviors"
          xmlns:mat="http://materialdesigninxaml.net/winfx/xaml/themes"
         xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
         xmlns:attached="clr-namespace:MinecraftBotManager.Asists"
         MaxWidth="{Binding RelativeSource={RelativeSource AncestorType=Border},Path=ActualWidth}"
         d:DesignHeight="450" d:DesignWidth="800">
<UserControl.Resources>        
    <converts:StringToVisibiltyConverter x:Key="StringToVisi"/>
</UserControl.Resources>
    <StackPanel Orientation="Horizontal">
    <TextBlock attached:TextBlockExtensions.BindableInlines="{Binding ColoredText}" TextWrapping="WrapWithOverflow" x:Name="Text" Foreground="White" FontFamily="JetBrains Mono" FontSize="14">
                       
        </TextBlock>
        <Button Click="Button_Click" Visibility="{Binding ElementName=Text,Path=Text,Converter={StaticResource StringToVisi}}" Margin="15,0,0,0" Height="auto" Width="auto" VerticalAlignment="Center" Padding="1" Background="Transparent" BorderThickness="0" >
            <Button.Content>
                <mat:PackIcon Kind="ContentCopy" Width="14" Margin="0" Height="auto"/>
            </Button.Content>
        </Button>
    </StackPanel>

ChatMessageVM

public List<Run> ColoredText { get; set; } = new List<Run>();

At the moment I have technical difficulties in migrating to UWP and Net Core (Yes, I have a Net Framework 4.8 project).

And one more little question: Is it right to bind Runs? I get json and it says what the text should look like.

Solution: I solved the problem. It turned out to be simple: I used Listbox in material design, where there is no virtualization.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source