avataren
Topic Author
Posts: 9
Joined: 02 Jun 2022, 13:11

ScrollViewer autoscroll with xaml behaviour

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.
                    
<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>
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: ScrollViewer autoscroll with xaml behaviour

17 Oct 2022, 14:49

Hi, the CallMethodAction is not implemented in Noesis, you should be getting an error message when parsing the xaml about an 'Unknow type'.
What other customers are doing is implementing a Behavior and attach it to the ScrollViewer. The behavior can expose an ItemsSource property to bind the collection, then you can hook to the CollectionChanged event and call ScrollToEnd on the associated ScrollViewer. Could you try that?
 
avataren
Topic Author
Posts: 9
Joined: 02 Jun 2022, 13:11

Re: ScrollViewer autoscroll with xaml behaviour

17 Oct 2022, 15:08

Ok, I'll give that a try.

I also tried to invoke a command by using
<b:Interaction.Triggers>
	<b:EventTrigger SourceObject="{Binding StickyLog}" EventName="CollectionChanged">
		<b:InvokeCommandAction Command="{Binding ElementName=CPanel, Path=ScrollToEndCommand}"/>
	</b:EventTrigger>
</b:Interaction.Triggers>
and have the command registered on the view codebehind, which works in Blend, but does not seem to trigger in my C++ code.
It looks like the InvokeCommandAction should work based on this https://www.noesisengine.com/docs/App.I ... ction.html
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: ScrollViewer autoscroll with xaml behaviour

18 Oct 2022, 10:21

It seems CollectionChanged event is not exposed to the reflection and EventTrigger is not firing the actions because of that.
I've created the ticket #2444 to fix this.

Implementing the behavior is the only way to solve this right now, sorry for the inconviniences.
 
avataren
Topic Author
Posts: 9
Joined: 02 Jun 2022, 13:11

Re: ScrollViewer autoscroll with xaml behaviour

18 Oct 2022, 11:27

I managed to get it to work by implementing a custom behaviour, thanks for the tip!
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: ScrollViewer autoscroll with xaml behaviour

20 Oct 2022, 10:53

Great, glad to help. Marking this as solved then.

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 17 guests