Skip to content

ScrollViewer expression animations extensions #3220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
afa5047
Merge pull request #10 from windows-toolkit/master
Sergio0694 Mar 15, 2020
e8cd4f7
Merge pull request #18 from windows-toolkit/master
Sergio0694 Mar 27, 2020
cbc80ef
Merge pull request #19 from windows-toolkit/master
Sergio0694 Apr 3, 2020
8c10171
Removed unnecessary using directive
Sergio0694 Apr 3, 2020
447434f
Added ScrollViewer expression animation extensions
Sergio0694 Apr 3, 2020
731eedb
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 Apr 19, 2020
bce0bb9
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 5, 2020
048f2fe
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 12, 2020
271bdfc
Added VisualProperty option
Sergio0694 May 12, 2020
a633fb4
Added example to ScrollViewerExtensions sample page
Sergio0694 May 12, 2020
f3fd843
Minor code refactoring
Sergio0694 May 12, 2020
b3d1281
Added C# sample code
Sergio0694 May 12, 2020
e35589f
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 12, 2020
28d31a6
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 13, 2020
c983cee
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 15, 2020
d4d6294
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 15, 2020
7050900
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 16, 2020
4d22f36
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 17, 2020
e7650f9
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 21, 2020
7c1cc4f
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 26, 2020
68ca8a4
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 26, 2020
68909c8
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 27, 2020
e40f3ad
Merge branch 'master' into feature/scroll-viewer-expression-animations
michael-hawker May 28, 2020
31a1b8d
Fixed XML docs for the ScrollViewerExtensions class
Sergio0694 May 28, 2020
e1a6caa
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 28, 2020
50b455b
Added more docs to the sample page
Sergio0694 May 28, 2020
1a2c610
Tweaked sample page a bit more
Sergio0694 May 28, 2020
74c5d32
Removed bounding boxes in sample page
Sergio0694 May 28, 2020
89bec43
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 28, 2020
67f631e
Merge branch 'master' into feature/scroll-viewer-expression-animations
Sergio0694 May 29, 2020
5c366a4
Fixed more XML docs
Sergio0694 May 29, 2020
9423f04
Merge branch 'master' into feature/scroll-viewer-expression-animations
michael-hawker May 29, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@
<Content Include="SamplePages\IconExtensions\IconExtensionsXaml.bind" />
<Content Include="SamplePages\WrapLayout\WrapLayout.bind" />
<Content Include="SamplePages\ObservableGroup\ObservableGroup.bind" />
<Content Include="SamplePages\ScrollViewerExtensions\ScrollViewerExtensionsXaml.bind" />
<Content Include="SamplePages\Triggers\CompareStateTrigger.bind" />
<Content Include="SamplePages\Triggers\IsEqualStateTrigger.bind" />
<Content Include="SamplePages\Triggers\FullScreenModeStateTrigger.bind" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,71 +1,10 @@
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:common="using:Microsoft.Toolkit.Uwp.SampleApp.Common"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
// C# - Scale can be applied to any UIElement. In this case it is an image called ToolkitLogo.
using Microsoft.Toolkit.Uwp.UI.Extensions;

<Page.Resources>
<common:DoubleTopThicknessConverter x:Key="DoubleTopThicknessConverter" />
</Page.Resources>
// Binds the Y scroll axis of the ScrollViewer to the Y translation axis of the target
listScrollViewer.StartExpressionAnimation(shapesPanel, Axis.Y);

<Grid>
<ListView Name="listView"
extensions:ScrollViewerExtensions.VerticalScrollBarMargin="{Binding MinHeight, ElementName=MyHeaderGrid, Converter={StaticResource DoubleTopThicknessConverter}}"
extensions:ScrollViewerExtensions.EnableMiddleClickScrolling="@[EnableMiddleClickScrolling:Bool:True]">
<ListView.Header>
<controls:ScrollHeader Mode="Sticky">
<Grid x:Name="MyHeaderGrid"
MinHeight="@[Header MinHeight:DoubleSlider:250:150-500]"
Background="{ThemeResource Brush-Sample-TransparentHeader}">
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock Margin="12"
FontSize="48"
FontWeight="Bold"
Foreground="{ThemeResource Brush-Main}"
Text="Scroll Header"
TextAlignment="Center"
TextWrapping="WrapWholeWords" />
<TextBlock Margin="12,0,12,12"
VerticalAlignment="Center"
Foreground="{ThemeResource Brush-Main}"
Text="The attached property allows you to assign a Thickness to both vertical and horizontal ScrollBar inside any container. In this example, VerticalScrollBarMargin is bound to StickyHeader's MinHeight. Moving MinHeight's Slider will move the vertical ScrollBar accordingly."
TextAlignment="Center"
TextWrapping="WrapWholeWords" />
</StackPanel>
</Grid>
</controls:ScrollHeader>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<Grid MinHeight="100"
Background="{ThemeResource Brush-Grey-03}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image x:Name="ToolkitLogo"
Grid.Column="0"
Width="100"
Height="100"
Margin="0,0,24,0"
Source="ms-appx:///Assets/ToolkitLogo.png" />
<TextBlock Grid.Column="1"
VerticalAlignment="Center"
Text="{Binding Title}"
TextTrimming="CharacterEllipsis" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="12,12,24,12" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>
</Page>
// It is also possible to synchronize different axes, as well as targeting
// different Visual properties. By default, the expression works with the
// Visual.Translate property, but Visual.Offset can be used as well.
listScrollViewer.StartExpressionAnimation(shapesPanel, Axis.X, Axis.Y, VisualProperty.Offset);
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<Grid MinHeight="100"
Background="{ThemeResource Brush-Grey-03}">
<Grid MinHeight="100" Background="Blue">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
Expand All @@ -66,5 +65,46 @@
</Style>
</ListView.ItemContainerStyle>
</ListView>
<StackPanel x:Name="shapesPanel"
HorizontalAlignment="Center"
Margin="{Binding MinHeight, ElementName=MyHeaderGrid, Converter={StaticResource DoubleTopThicknessConverter}}"
Padding="88"
Spacing="32">
<Polygon Height="100"
Width="100"
Points="0,0 0,72 44,36"
Stroke="DarkGreen"
Fill="Green"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Spacing="4"
Height="84"
Width="100">
<Polygon Points="0,0 0,56 32,28"
Stroke="Blue"
Fill="DodgerBlue"/>
<Polygon Points="0,0 0,56 32,28"
Stroke="Blue"
Fill="DodgerBlue"/>
</StackPanel>
<TextBlock
Height="100"
FontSize="24"
TextAlignment="Center">
<Run Text="Look at me, I'm floating between"/>
<LineBreak/>
<Run Text="two different ListView items!"/>
</TextBlock>
<Polygon Height="100"
Width="100"
Points="0,0 0,60 60,60 60,0"
Stroke="DarkRed"
Fill="Crimson"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</StackPanel>
</Grid>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

using System.Collections.ObjectModel;
using Microsoft.Toolkit.Uwp.SampleApp.Models;
using Microsoft.Toolkit.Uwp.UI.Controls;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
Expand All @@ -35,6 +33,14 @@ public void OnXamlRendered(FrameworkElement control)
if (listView != null)
{
listView.ItemsSource = _items;

var shapesPanel = control.FindChildByName("shapesPanel") as StackPanel;
if (shapesPanel != null)
{
var listScrollViewer = listView.FindDescendant<ScrollViewer>();

listScrollViewer?.StartExpressionAnimation(shapesPanel, Axis.Y);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:common="using:Microsoft.Toolkit.Uwp.SampleApp.Common"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.Resources>
<common:DoubleTopThicknessConverter x:Key="DoubleTopThicknessConverter" />
</Page.Resources>

<Grid>
<ListView Name="listView"
extensions:ScrollViewerExtensions.VerticalScrollBarMargin="{Binding MinHeight, ElementName=MyHeaderGrid, Converter={StaticResource DoubleTopThicknessConverter}}"
extensions:ScrollViewerExtensions.EnableMiddleClickScrolling="@[EnableMiddleClickScrolling:Bool:True]">
<ListView.Header>
<controls:ScrollHeader Mode="Sticky">
<Grid x:Name="MyHeaderGrid"
MinHeight="@[Header MinHeight:DoubleSlider:250:150-500]"
Background="{ThemeResource Brush-Sample-TransparentHeader}">
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock Margin="12"
FontSize="48"
FontWeight="Bold"
Foreground="{ThemeResource Brush-Main}"
Text="Scroll Header"
TextAlignment="Center"
TextWrapping="WrapWholeWords" />
<TextBlock Margin="12,0,12,12"
VerticalAlignment="Center"
Foreground="{ThemeResource Brush-Main}"
Text="The attached property allows you to assign a Thickness to both vertical and horizontal ScrollBar inside any container. In this example, VerticalScrollBarMargin is bound to StickyHeader's MinHeight. Moving MinHeight's Slider will move the vertical ScrollBar accordingly."
TextAlignment="Center"
TextWrapping="WrapWholeWords" />
</StackPanel>
</Grid>
</controls:ScrollHeader>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<Grid MinHeight="100"
Background="{ThemeResource Brush-Grey-03}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image x:Name="ToolkitLogo"
Grid.Column="0"
Width="100"
Height="100"
Margin="0,0,24,0"
Source="ms-appx:///Assets/ToolkitLogo.png" />
<TextBlock Grid.Column="1"
VerticalAlignment="Center"
Text="{Binding Title}"
TextTrimming="CharacterEllipsis" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Padding" Value="12,12,24,12" />
</Style>
</ListView.ItemContainerStyle>
</ListView>

<!--This is the panel that will be animated in sync with the main ScrollViewer control inside
the ListView in the page, using the ScrollViewerExtensions leveraging composition ExpressionAnimations.
We use x:Name here to be able to reference the panel from code behind and start the animation.
To inspect the C# code beind used, switch to the "Code" tab in this sample page.-->
<StackPanel x:Name="shapesPanel"
HorizontalAlignment="Center"
Margin="{Binding MinHeight, ElementName=MyHeaderGrid, Converter={StaticResource DoubleTopThicknessConverter}}"
Padding="88"
Spacing="32">
<Polygon Height="100"
Width="100"
Points="0,0 0,72 44,36"
Stroke="DarkGreen"
Fill="Green"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
<StackPanel Orientation="Horizontal"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Spacing="4"
Height="84"
Width="100">
<Polygon Points="0,0 0,56 32,28"
Stroke="Blue"
Fill="DodgerBlue"/>
<Polygon Points="0,0 0,56 32,28"
Stroke="Blue"
Fill="DodgerBlue"/>
</StackPanel>
<TextBlock
Height="100"
FontSize="24"
TextAlignment="Center">
<Run Text="Look at me, I'm floating between"/>
<LineBreak/>
<Run Text="two different ListView items!"/>
</TextBlock>
<Polygon Height="100"
Width="100"
Points="0,0 0,60 60,60 60,0"
Stroke="DarkRed"
Fill="Crimson"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</StackPanel>
</Grid>
</Page>
3 changes: 2 additions & 1 deletion Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,8 @@
"Type": "ScrollViewerExtensionsPage",
"About": "Extensions for all controls that contain a ScrollViewer like ListView.",
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI/Extensions/ScrollViewer",
"XamlCodeFile": "ScrollViewerExtensionsCode.bind",
"XamlCodeFile": "ScrollViewerExtensionsXaml.bind",
"CodeFile": "ScrollViewerExtensionsCode.bind",
"Icon": "/Assets/Helpers.png",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/extensions/ScrollViewerExtensions.md"
},
Expand Down
22 changes: 22 additions & 0 deletions Microsoft.Toolkit.Uwp.UI/Extensions/ScrollViewer/Enums/Axis.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.Toolkit.Uwp.UI.Extensions
{
/// <summary>
/// Indicates an axis in the 2D space
/// </summary>
public enum Axis
{
/// <summary>
/// The X axis (horizontal)
/// </summary>
X,

/// <summary>
/// The Y axis (vertical)
/// </summary>
Y
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Windows.UI.Composition;

namespace Microsoft.Toolkit.Uwp.UI.Extensions
{
/// <summary>
/// Indicates a property of a <see cref="Visual"/> object.
/// </summary>
public enum VisualProperty
{
/// <summary>
/// The offset property of a <see cref="Visual"/> object.
/// </summary>
Offset,

/// <summary>
/// The translation property of a <see cref="Visual"/> object.
/// </summary>
Translation
}
}
Loading