Created
March 20, 2014 08:40
-
-
Save runceel/9659620 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Page | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:local="using:App11" | |
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:Core="using:Microsoft.Xaml.Interactions.Core" xmlns:Media="using:Microsoft.Xaml.Interactions.Media" | |
x:Class="App11.MainPage" | |
mc:Ignorable="d"> | |
<Page.Resources> | |
<Storyboard x:Name="Storyboard1"> | |
<DoubleAnimation Duration="0:0:1" To="391.184" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="button" d:IsOptimized="True"/> | |
<DoubleAnimation Duration="0:0:1" To="403.762" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="button" d:IsOptimized="True"/> | |
</Storyboard> | |
</Page.Resources> | |
<Page.DataContext> | |
<local:MainPageViewModel /> | |
</Page.DataContext> | |
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | |
<Interactivity:Interaction.Behaviors> | |
<local:StoryboardCompletedTrigger TargetStoryboard="{StaticResource Storyboard1}"> | |
<local:StoryboardCompletedTrigger.Actions> | |
<Core:InvokeCommandAction Command="{Binding StoryboardCompletedCommand, Mode=OneWay}"/> | |
</local:StoryboardCompletedTrigger.Actions> | |
</local:StoryboardCompletedTrigger> | |
</Interactivity:Interaction.Behaviors> | |
<Button x:Name="button" Content="{Binding Message}" HorizontalAlignment="Left" Margin="79,57,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5"> | |
<Button.RenderTransform> | |
<CompositeTransform/> | |
</Button.RenderTransform> | |
<Interactivity:Interaction.Behaviors> | |
<Core:EventTriggerBehavior EventName="Click"> | |
<Media:ControlStoryboardAction Storyboard="{StaticResource Storyboard1}"/> | |
</Core:EventTriggerBehavior> | |
</Interactivity:Interaction.Behaviors> | |
</Button> | |
</Grid> | |
</Page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Xaml.Interactivity; | |
using Windows.UI.Xaml; | |
using Windows.UI.Xaml.Media.Animation; | |
namespace App11 | |
{ | |
public class StoryboardCompletedTrigger : DependencyObject, IBehavior | |
{ | |
public ActionCollection Actions | |
{ | |
get | |
{ | |
var result = (ActionCollection)GetValue(ActionsProperty); | |
if (result == null) | |
{ | |
result = new ActionCollection(); | |
this.Actions = result; | |
} | |
return result; | |
} | |
set { SetValue(ActionsProperty, value); } | |
} | |
// Using a DependencyProperty as the backing store for Actions. This enables animation, styling, binding, etc... | |
public static readonly DependencyProperty ActionsProperty = | |
DependencyProperty.Register("Actions", | |
typeof(ActionCollection), | |
typeof(StoryboardCompletedTrigger), | |
new PropertyMetadata(null)); | |
public Storyboard TargetStoryboard | |
{ | |
get { return (Storyboard)GetValue(TargetStoryboardProperty); } | |
set { SetValue(TargetStoryboardProperty, value); } | |
} | |
public static readonly DependencyProperty TargetStoryboardProperty = | |
DependencyProperty.Register("TargetStoryboard", | |
typeof(Storyboard), | |
typeof(StoryboardCompletedTrigger), | |
new PropertyMetadata(null)); | |
public DependencyObject AssociatedObject { get; set; } | |
public void Attach(DependencyObject associatedObject) | |
{ | |
if (this.TargetStoryboard == null) | |
{ | |
return; | |
} | |
this.TargetStoryboard.Completed += TargetStoryboard_Completed; | |
} | |
private void TargetStoryboard_Completed(object sender, object e) | |
{ | |
Interaction.ExecuteActions(this, this.Actions, e); | |
} | |
public void Detach() | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment