Skip to content

Commit 3901a2f

Browse files
Merge pull request #346 from Sergio0694/feature/scrollviewer-expression-animations
Scrollviewer expression animations
2 parents 814b828 + ddae46d commit 3901a2f

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

docs/extensions/ScrollViewerExtensions.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: ScrollViewerEx provides a simple way to manage Margin for any Scrol
55
keywords: windows 10, uwp, windows community toolkit, uwp community toolkit, uwp toolkit, ScrollViewer, extentions
66
---
77

8-
# ScrollViewer extentions
8+
# ScrollViewer extensions
99

1010
The [ScrollViewerExtensions](https://docs.microsoft.com/en-us/dotnet/api/microsoft.toolkit.uwp.ui.extensions.scrollviewerextensions) provide extension methods to improve your ScrollViewer implementation.
1111

@@ -115,7 +115,7 @@ MiddleClickScrolling allows you to scroll by click middle mouse button (scroll w
115115

116116
### Edit Existing Resource File
117117

118-
You can easily edit the existing resource file to customise the cursor depending upon your needs.
118+
You can easily edit the existing resource file to customize the cursor depending upon your needs.
119119

120120
1. Follow the above steps to add the resource file
121121
2. Open MiddleClickScrolling-CursorType.res file in Visual Studio
@@ -128,6 +128,62 @@ You can easily edit the existing resource file to customise the cursor depending
128128
| -- | -- | -- |
129129
| EnableMiddleClickScrolling | bool | Set `true` to enable middle click scrolling |
130130

131+
## Expression animations
132+
133+
The `StartExpressionAnimation` methods provide a way to easily start a composition expression animation to sync a `ScrollViewer` instance with another control. This binds the manipulation status on a `ScrollViewer` property set with either the translation or the offset of another visual element, to follow or mirror the motion in the source `ScrollViewer`.
134+
135+
### Example
136+
137+
```xml
138+
<Grid>
139+
140+
<!--This is a ListView we can use to display a series of items. It will
141+
contain the ScrollViewer that will be targeted by the expression animation.-->
142+
<ListView Name="listView">
143+
<ListView.ItemTemplate>
144+
<DataTemplate>
145+
<Image Width="100"
146+
Height="100"
147+
Source="ms-appx:///Assets/ToolkitLogo.png" />
148+
</DataTemplate>
149+
</ListView.ItemTemplate>
150+
</ListView>
151+
152+
<!--This is the panel that will be animated in sync with the main ScrollViewer control
153+
inside the ListView in the page, using the ScrollViewerExtensions leveraging composition
154+
ExpressionAnimations. Note how the panel is not inside the ListView, but it's just
155+
rendering "fixed" items right on top of the ListView. We can use the expression animation
156+
to "bind" the scrolling of the ListView and keep the panel "in sync" with it.-->
157+
<StackPanel x:Name="shapesPanel">
158+
<Polygon Height="100"
159+
Width="100"
160+
Points="0,0 0,72 44,36"
161+
Stroke="DarkGreen"
162+
Fill="Green"
163+
VerticalAlignment="Center"
164+
HorizontalAlignment="Center"/>
165+
</StackPanel>
166+
</Grid>
167+
```
168+
169+
```csharp
170+
using Microsoft.Toolkit.Uwp.UI.Extensions;
171+
172+
ScrollViewer scrollViewer = listView.FindDescendant<ScrollViewer>();
173+
174+
// Binds the Y scroll axis of the ScrollViewer to the Y translation axis of the target
175+
listScrollViewer.StartExpressionAnimation(shapesPanel, Axis.Y);
176+
177+
// It is also possible to synchronize different axes, as well as targeting
178+
// different Visual properties. By default, the expression works with the
179+
// Visual.Translate property, but Visual.Offset can be used as well.
180+
listScrollViewer.StartExpressionAnimation(shapesPanel, Axis.X, Axis.Y, VisualProperty.Offset);
181+
```
182+
183+
### Sample output
184+
185+
![Expression Animations](../resources/images/Extensions/ScrollViewerExpressionAnimation.gif)
186+
131187
## Sample Project
132188

133189
[ScrollViewerExtensions sample page Source](https://github.com/Microsoft/WindowsCommunityToolkit//tree/master/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/ScrollViewerExtensions). You can [see this in action](uwpct://Extensions?sample=ScrollViewerExtensions) in the [Windows Community Toolkit Sample App](http://aka.ms/uwptoolkitapp).
Loading

0 commit comments

Comments
 (0)