These are chat archives for AvaloniaUI/Avalonia

28th
Nov 2018
Jeremy Koritzinsky
@jkoritzinsky
Nov 28 2018 00:49
The core library though is structured to be cross-platform
nicolasr75
@nicolasr75
Nov 28 2018 12:57

I want to create a scrollable view of log messages with a maximum capacity. Once this capacity is reached, the newest message kicks out the oldest one. Currently I use ScrollViewer/ItemsControl/TextBlock

<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">  
  <ItemsControl Items="{Binding LogMessages}">
    <ItemsControl.ItemTemplate>
      <DataTemplate>
        <TextBlock x:Name="DataItem" Text="{Binding}"/>
      </DataTemplate>
    </ItemsControl.ItemTemplate>
  </ItemsControl>
</ScrollViewer>

This works well for a few hundred messages but starts to produce high CPU load with a capacity of >1000. Is there a better way to do this?

Benedikt Stebner
@Gillibald
Nov 28 2018 13:05
Try to use a VirtualizingStackPanel as the ItemsPanel
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">  
  <ItemsControl Items="{Binding LogMessages}">
  <ItemsControl.ItemsPanel>
      <VirtualizingStackPanel/>
  </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
      <DataTemplate>
        <TextBlock x:Name="DataItem" Text="{Binding}"/>
      </DataTemplate>
    </ItemsControl.ItemTemplate>
  </ItemsControl>
</ScrollViewer>
Could be that you have to use a ListBox for virtualization not sure
Benedikt Stebner
@Gillibald
Nov 28 2018 13:22
Steven Kirk
@grokys
Nov 28 2018 14:17
@Gillibald i don't think that will work without re-templating the control to include VirtualizationMode="Simple" on the ItemsControl
it'd be better to use ListBox for this
might be worth adding SelectionMode.None for when people don't want the items to be selectable
nicolasr75
@nicolasr75
Nov 28 2018 14:33
@grokys the advantage of ItemsControl with TextBlock is that people can select and copy specific messages. I guess most people would expect that to work.
Steven Kirk
@grokys
Nov 28 2018 14:34
you can put a TextBlock in the listbox items though too right?
nicolasr75
@nicolasr75
Nov 28 2018 14:34
Ok, I'll try that
MonkAlex
@MonkAlex
Nov 28 2018 17:15
TextBlock not support Inlines now?
What about #1689 status?
Benedikt Stebner
@Gillibald
Nov 28 2018 18:01
I am currently working on skia support for that. Will be testable in the next weeks or so. Depends on how much time I have to work on it.