Skip to content

Commit

Permalink
Feat: Add AnimatedVisualSource selection (#1452)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description
As title

## Motivation and Context
Sometimes need to quickly checkout the animation effects, so I added it.

## How Has This Been Tested?
Manual

## Screenshots (if appropriate):

![image](https://github.com/microsoft/WinUI-Gallery/assets/42881734/3fe2568f-6650-4e2a-94b6-5e7ad7edd97c)
  • Loading branch information
HO-COOH authored Mar 4, 2024
1 parent 906d35a commit 4039b3b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
20 changes: 16 additions & 4 deletions WinUIGallery/ControlPages/AnimatedIconPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:animatedvisuals="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals"
xmlns:local="using:WinUIGallery"
xmlns:pages="using:WinUIGallery.ControlPages"
mc:Ignorable="d">
<StackPanel>
<local:ControlExample x:Name="AnimatedIconExample1" HeaderText="Adding AnimatedIcon to a button"
Expand All @@ -21,17 +22,28 @@
For guidance on how to properly structure your animation file see the AnimatedIcon Guidance page.<LineBreak></LineBreak>
</TextBlock>
<Button PointerEntered="Button_PointerEntered" PointerExited="Button_PointerExited" Width="75" AutomationProperties.Name="AnimatedIcon Example">
<AnimatedIcon x:Name="SearchAnimatedIcon">
<AnimatedIcon.Source>
<animatedvisuals:AnimatedFindVisualSource/>
</AnimatedIcon.Source>
<AnimatedIcon x:Name="SearchAnimatedIcon" Source="{x:Bind pages:AnimatedIconPage.GetAnimationSourceFromString(AnimatedVisualSourceSelection.SelectedItem), Mode=OneWay}">
<AnimatedIcon.FallbackIconSource>
<SymbolIconSource Symbol="Find"/>
</AnimatedIcon.FallbackIconSource>
</AnimatedIcon>
</Button>
</StackPanel>
</local:ControlExample.Example>
<local:ControlExample.Options>
<ComboBox x:Name="AnimatedVisualSourceSelection" Header="Kind" SelectedIndex="4" VerticalAlignment="Center" MinWidth="340">
<x:String>AnimatedBackVisualSource</x:String>
<x:String>AnimatedChevronDownSmallVisualSource</x:String>
<x:String>AnimatedChevronRightDownSmallVisualSource</x:String>
<x:String>AnimatedChevronUpDownSmallVisualSource</x:String>
<x:String>AnimatedFindVisualSource</x:String>
<x:String>AnimatedGlobalNavigationButtonVisualSource</x:String>
<x:String>AnimatedSettingsVisualSource</x:String>
</ComboBox>
</local:ControlExample.Options>
<local:ControlExample.Substitutions>
<local:ControlExampleSubstitution Key="AnimatedVisualSourceKind" Value="{x:Bind AnimatedVisualSourceSelection.SelectedItem, Mode=OneWay}"/>
</local:ControlExample.Substitutions>
</local:ControlExample>
<local:ControlExample x:Name="AnimatedIconExample2" HeaderText="Adding AnimatedIcon to a NavigationView" XamlSource="Icons/AnimatedIconSample2_xaml.txt">
<local:ControlExample.Example>
Expand Down
17 changes: 17 additions & 0 deletions WinUIGallery/ControlPages/AnimatedIconPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.UI.Xaml.Controls.AnimatedVisuals;

namespace WinUIGallery.ControlPages
{
Expand All @@ -31,5 +32,21 @@ private void Button_PointerExited(object sender, PointerRoutedEventArgs e)
{
AnimatedIcon.SetState(this.SearchAnimatedIcon, "Normal");
}

public static IAnimatedVisualSource2 GetAnimationSourceFromString(object selection)
{
string name = (string)selection;
switch (name)
{
case "AnimatedBackVisualSource": return new AnimatedBackVisualSource();
case "AnimatedChevronDownSmallVisualSource": return new AnimatedChevronDownSmallVisualSource();
case "AnimatedChevronRightDownSmallVisualSource": return new AnimatedChevronRightDownSmallVisualSource();
case "AnimatedChevronUpDownSmallVisualSource": return new AnimatedChevronUpDownSmallVisualSource();
case "AnimatedFindVisualSource": return new AnimatedFindVisualSource();
case "AnimatedGlobalNavigationButtonVisualSource": return new AnimatedGlobalNavigationButtonVisualSource();
case "AnimatedSettingsVisualSource": return new AnimatedSettingsVisualSource();
default: return null;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Button PointerEntered="Button_PointerEntered" PointerExited="Button_PointerExited" Width="75">
<AnimatedIcon x:Name="SearchAnimatedIcon">
<AnimatedIcon.Source>
<animatedvisuals:AnimatedFindVisualSource/>
<animatedvisuals:$(AnimatedVisualSourceKind)/>
</AnimatedIcon.Source>
<AnimatedIcon.FallbackIconSource>
<SymbolIconSource Symbol="Find"/>
Expand Down

0 comments on commit 4039b3b

Please sign in to comment.