ScrollViewer autoscroll with xaml behaviour
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>
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: ScrollViewer autoscroll with xaml behaviour
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?
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?
Re: ScrollViewer autoscroll with xaml behaviour
Ok, I'll give that a try.
I also tried to invoke a command by using
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
I also tried to invoke a command by using
Code: Select all
<b:Interaction.Triggers>
<b:EventTrigger SourceObject="{Binding StickyLog}" EventName="CollectionChanged">
<b:InvokeCommandAction Command="{Binding ElementName=CPanel, Path=ScrollToEndCommand}"/>
</b:EventTrigger>
</b:Interaction.Triggers>
It looks like the InvokeCommandAction should work based on this https://www.noesisengine.com/docs/App.I ... ction.html
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: ScrollViewer autoscroll with xaml behaviour
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.
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.
Re: ScrollViewer autoscroll with xaml behaviour
I managed to get it to work by implementing a custom behaviour, thanks for the tip!
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: ScrollViewer autoscroll with xaml behaviour
Great, glad to help. Marking this as solved then.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 17 guests