ScrollViewer autoscroll with xaml behaviour
Posted: 17 Oct 2022, 10:50
Hi, I made a simple "log viewer" in xaml, based on a ScrollViewer. I set up a behaviour trigger that will call "ScrollToEnd" everytime the underlying collection changes, and this works well in my Blend testcode, but not when I implement it in C++.
Do I need to manually send out the CollectionChanged event, or is there something else I am missing here?
For the ObservableCollection items I made a simple class that inherits basecomponent, and it is showing up in the scrollviewer when I add items to it, but the scrollbar is not changing.
this is the markup I use.
Do I need to manually send out the CollectionChanged event, or is there something else I am missing here?
For the ObservableCollection items I made a simple class that inherits basecomponent, and it is showing up in the scrollviewer when I add items to it, but the scrollbar is not changing.
this is the markup I use.
Code: Select all
<DockPanel MaxHeight="160" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3">
<ScrollViewer VerticalScrollBarVisibility="Auto" Padding="5" x:Name="MessageScroll">
<ItemsControl ItemsSource="{Binding StickyLog}">
<b:Interaction.Triggers>
<b:EventTrigger SourceObject="{Binding StickyLog}" EventName="CollectionChanged">
<b:CallMethodAction MethodName="ScrollToEnd" TargetObject="{Binding ElementName=MessageScroll}"/>
</b:EventTrigger>
</b:Interaction.Triggers>
<ItemsControl.ItemTemplate>
<DataTemplate>
... template stuff
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</DockPanel>