Skip to content

Commit f69d53b

Browse files
authored
Added animations to the widgets (#2213)
1 parent a3ed28d commit f69d53b

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

Files/UserControls/Widgets/DrivesWidget.xaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
x:Class="Files.DrivesWidget"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:animations="using:Microsoft.Toolkit.Uwp.UI.Animations"
56
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
67
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
79
xmlns:local="using:Files"
810
xmlns:local2="using:Files.Filesystem"
911
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -37,7 +39,13 @@
3739
</muxc:ItemsRepeater.Layout>
3840
<muxc:ItemsRepeater.ItemTemplate>
3941
<DataTemplate x:DataType="local2:DriveItem">
40-
<Grid>
42+
<Grid
43+
extensions:VisualExtensions.CenterPoint="80,45,0"
44+
PointerEntered="GridScaleUp"
45+
PointerExited="GridScaleNormal">
46+
<animations:Implicit.Animations>
47+
<animations:ScaleAnimation Duration="0:0:0.5" />
48+
</animations:Implicit.Animations>
4149
<Grid.Resources>
4250
<ResourceDictionary>
4351
<ResourceDictionary.ThemeDictionaries>
@@ -67,7 +75,6 @@
6775
Style="{StaticResource ButtonRevealStyle}"
6876
Tag="{x:Bind Path}"
6977
ToolTipService.ToolTip="{x:Bind Text}">
70-
7178
<Grid
7279
Margin="12"
7380
HorizontalAlignment="Stretch"

Files/UserControls/Widgets/DrivesWidget.xaml.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
using Files.View_Models;
33
using System.Collections.Generic;
44
using System.Collections.ObjectModel;
5+
using System.Numerics;
56
using Windows.UI.Xaml;
67
using Windows.UI.Xaml.Controls;
8+
using Windows.UI.Xaml.Hosting;
79

810
namespace Files
911
{
@@ -28,5 +30,21 @@ private void Button_Click(object sender, RoutedEventArgs e)
2830

2931
App.CurrentInstance.InstanceViewModel.IsPageTypeNotHome = true; // show controls that were hidden on the home page
3032
}
33+
34+
private void GridScaleUp(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
35+
{
36+
// Source for the scaling: https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Implicit%20Animations/ImplicitAnimationsPage.xaml.cs
37+
// Search for "Scale Element".
38+
var element = sender as UIElement;
39+
var visual = ElementCompositionPreview.GetElementVisual(element);
40+
visual.Scale = new Vector3(1.03f, 1.03f, 1);
41+
}
42+
43+
private void GridScaleNormal(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
44+
{
45+
var element = sender as UIElement;
46+
var visual = ElementCompositionPreview.GetElementVisual(element);
47+
visual.Scale = new Vector3(1);
48+
}
3149
}
3250
}

Files/UserControls/Widgets/LibraryCards.xaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
x:Class="Files.LibraryCards"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:animations="using:Microsoft.Toolkit.Uwp.UI.Animations"
56
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
67
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8+
xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
79
xmlns:local="using:Files"
810
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
911
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
@@ -27,7 +29,13 @@
2729
</muxc:ItemsRepeater.Layout>
2830
<muxc:ItemsRepeater.ItemTemplate>
2931
<DataTemplate x:DataType="local:FavoriteLocationItem">
30-
<Grid>
32+
<Grid
33+
extensions:VisualExtensions.CenterPoint="80,45,0"
34+
PointerEntered="GridScaleUp"
35+
PointerExited="GridScaleNormal">
36+
<animations:Implicit.Animations>
37+
<animations:ScaleAnimation Duration="0:0:0.5" />
38+
</animations:Implicit.Animations>
3139
<Grid.Resources>
3240
<ResourceDictionary>
3341
<ResourceDictionary.ThemeDictionaries>

Files/UserControls/Widgets/LibraryCards.xaml.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using Files.View_Models;
22
using Microsoft.Toolkit.Uwp.Extensions;
33
using System.Collections.Generic;
4+
using System.Numerics;
45
using Windows.UI.Xaml;
56
using Windows.UI.Xaml.Controls;
7+
using Windows.UI.Xaml.Hosting;
68

79
namespace Files
810
{
@@ -23,6 +25,22 @@ public LibraryCards()
2325
foreach (var item in itemsAdded) { item.AutomationProperties = item.Text; }
2426
}
2527

28+
private void GridScaleUp(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
29+
{
30+
// Source for the scaling: https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Implicit%20Animations/ImplicitAnimationsPage.xaml.cs
31+
// Search for "Scale Element".
32+
var element = sender as UIElement;
33+
var visual = ElementCompositionPreview.GetElementVisual(element);
34+
visual.Scale = new Vector3(1.03f, 1.03f, 1);
35+
}
36+
37+
private void GridScaleNormal(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
38+
{
39+
var element = sender as UIElement;
40+
var visual = ElementCompositionPreview.GetElementVisual(element);
41+
visual.Scale = new Vector3(1);
42+
}
43+
2644
private void Button_Click(object sender, RoutedEventArgs e)
2745
{
2846
string NavigationPath = ""; // path to navigate

0 commit comments

Comments
 (0)