Add InvokeActionsActivity to Behaviors Package and Sample

This commit is contained in:
michael-hawker 2021-01-08 12:18:35 -08:00
Родитель 04939b5c42
Коммит 9e4f4bc3b9
6 изменённых файлов: 132 добавлений и 0 удалений

Двоичные данные
Microsoft.Toolkit.Uwp.SampleApp/Assets/Llama.mp3 Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -132,6 +132,7 @@
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
<Content Include="Assets\BrushAssets\TileTexture.png" />
<Content Include="Assets\BrushAssets\NoiseTexture.png" />
<Content Include="Assets\Llama.mp3" />
<Content Include="Assets\mslogo.png" />
<Content Include="Assets\NotificationAssets\Cloudy-Square.png" />
<Content Include="Assets\NotificationAssets\Cloudy.png" />
@ -588,6 +589,7 @@
<Content Include="SamplePages\Animations\Effects\FadeBehaviorCode.bind" />
<Content Include="SamplePages\Animations\Effects\FadeBehaviorXaml.bind" />
<Content Include="SamplePages\Animations\Activities\StartAnimationActivity.bind" />
<Content Include="SamplePages\Animations\Activities\InvokeActionsActivity.bind" />
</ItemGroup>
<ItemGroup>
<Compile Include="App.xaml.cs">

Просмотреть файл

@ -0,0 +1,54 @@
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
xmlns:mediaactions="using:Microsoft.Xaml.Interactions.Media"
xmlns:ani="using:Microsoft.Toolkit.Uwp.UI.Animations"
xmlns:behaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors.Animations"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
mc:Ignorable="d">
<Button Background="Gray" Width="200" Height="200" HorizontalAlignment="Center" VerticalAlignment="Center">
<ani:Explicit.Animations>
<ani:AnimationSet x:Name="MoveAnimation" IsSequential="True">
<ani:StartAnimationActivity Animation="{Binding ElementName=FadeOutAnimation}"/>
<ani:InvokeActionsActivity>
<interactions:ChangePropertyAction TargetObject="{Binding ElementName=MyText}" PropertyName="Foreground" Value="Purple"/>
<mediaactions:PlaySoundAction Source="Assets/Llama.mp3"/>
</ani:InvokeActionsActivity>
<ani:StartAnimationActivity Delay="0:0:2" Animation="{Binding ElementName=FadeInAnimation}"/>
</ani:AnimationSet>
</ani:Explicit.Animations>
<TextBlock x:Name="MyText" Text="🦙 Text">
<ani:Explicit.Animations>
<ani:AnimationSet x:Name="FadeOutAnimation">
<ani:OpacityAnimation From="1"
To="0"
Duration="0:0:1"
Delay="0"
EasingType="Linear"
EasingMode="EaseOut"/>
</ani:AnimationSet>
<ani:AnimationSet x:Name="FadeInAnimation">
<ani:OpacityAnimation From="0"
To="1"
Duration="0:0:1"
Delay="0"
EasingType="Linear"
EasingMode="EaseOut"/>
</ani:AnimationSet>
</ani:Explicit.Animations>
</TextBlock>
<interactivity:Interaction.Behaviors>
<interactions:EventTriggerBehavior EventName="Click">
<interactions:ChangePropertyAction TargetObject="{Binding ElementName=MyText}" PropertyName="Foreground" Value="White"/>
<behaviors:StartAnimationAction Animation="{Binding ElementName=MoveAnimation}"/>
</interactions:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Button>
</Page>

Просмотреть файл

@ -4,8 +4,11 @@
xmlns:ani="using:Microsoft.Toolkit.Uwp.UI.Animations"
xmlns:anibehaviors="using:Microsoft.Toolkit.Uwp.UI.Behaviors.Animations"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:media="using:Microsoft.Toolkit.Uwp.UI.Media"
xmlns:mediaactions="using:Microsoft.Xaml.Interactions.Media"
xmlns:triggers="using:Microsoft.Toolkit.Uwp.UI.Triggers"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">
@ -30,6 +33,7 @@
<ani:BlurEffectAnimation />
<ani:OpacityAnimation />
<ani:StartAnimationActivity />
<ani:InvokeActionsActivity />
</ani:AnimationSet>
</ani:Explicit.Animations>
<media:UIElementExtensions.VisualFactory>
@ -37,5 +41,13 @@
<media:OpacityEffect />
</media:PipelineVisualFactory>
</media:UIElementExtensions.VisualFactory>
<!-- External -->
<interactivity:Interaction.Behaviors>
<interactions:EventTriggerBehavior EventName="Loaded">
<interactions:ChangePropertyAction />
<mediaactions:PlaySoundAction />
</interactions:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Grid>
</Page>

Просмотреть файл

@ -468,6 +468,14 @@
"XamlCodeFile": "/SamplePages/Animations/Activities/StartAnimationActivity.bind",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/animations/Fade.md"
},
{
"Name": "InvokeActionsActivity",
"Subcategory": "Activities",
"About": "Activity chaining Actions from the Behaviors package into an Animation schedule.",
"CodeUrl": "https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Behaviors/Animations",
"XamlCodeFile": "/SamplePages/Animations/Activities/InvokeActionsActivity.bind",
"DocumentationUrl": "https://raw.githubusercontent.com/MicrosoftDocs/WindowsCommunityToolkitDocs/master/docs/animations/Fade.md"
},
{
"Name": "Fade",
"Subcategory": "Effect",

Просмотреть файл

@ -0,0 +1,56 @@
// 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 System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Toolkit.Uwp.UI.Animations;
using Microsoft.Xaml.Interactivity;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Markup;
namespace Microsoft.Toolkit.Uwp.UI.Animations
{
/// <summary>
/// The <see cref="InvokeActionsActivity"/> is an <see cref="Activity"/> which allows bridging to performing any behavior based <see cref="IAction"/> within the schedule.
/// </summary>
[ContentProperty(Name = nameof(Actions))]
public class InvokeActionsActivity : Activity
{
/// <summary>
/// Identifies the <seealso cref="Actions"/> dependency property.
/// </summary>
public static readonly DependencyProperty ActionsProperty = DependencyProperty.Register(
nameof(Actions),
typeof(ActionCollection),
typeof(InvokeActionsActivity),
new PropertyMetadata(null));
/// <summary>
/// Gets the collection of actions associated with the behavior. This is a dependency property.
/// </summary>
public ActionCollection Actions
{
get
{
if (GetValue(ActionsProperty) is not ActionCollection actionCollection)
{
actionCollection = new ActionCollection();
SetValue(ActionsProperty, actionCollection);
}
return actionCollection;
}
}
/// <inheritdoc/>
public override async Task InvokeAsync(UIElement element, CancellationToken token)
{
await base.InvokeAsync(element, token);
Interaction.ExecuteActions(element, Actions, EventArgs.Empty);
}
}
}