I need to bind my storyboard's Completed to my VM DelegateCommand, so I found this topic.
But for some reason it doesn't work for me. Help me please figure it out.
My template with storyboard
<Grid.Triggers>
<EventTrigger RoutedEvent="Button.Click" SourceName="AddButton2">
<BeginStoryboard Name="MyBeginStoryboard">
<Storyboard
TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"
local1:StoryboardHelper.CompletedCommand="{Binding Path=OpenPanelCommand}"
>
<DoubleAnimation
Storyboard.TargetName="panelControl"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"
Duration="0:0:01" From="0" To="-700"
/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
ViewModel constructor, where OpenPanelCommand has a type ICommand:
OpenPanelCommand = new DelegateCommand(() => { PanelOpened = true; });
StoryboardHelper from link above:
public static class StoryboardHelper
{
public static readonly DependencyProperty CompletedCommandProperty = DependencyProperty.RegisterAttached("CompletedCommand", typeof(ICommand), typeof(StoryboardHelper), new PropertyMetadata(null, OnCompletedCommandChanged));
public static readonly DependencyProperty CompletedCommandParameterProperty = DependencyProperty.RegisterAttached("CompletedCommandParameter", typeof(object), typeof(StoryboardHelper), new PropertyMetadata(null));
public static void SetCompletedCommand(DependencyObject o, ICommand value)
{
o.SetValue(CompletedCommandProperty, value);
}
public static ICommand GetCompletedCommand(DependencyObject o)
{
return (ICommand)o.GetValue(CompletedCommandProperty);
}
public static void SetCompletedCommandParameter(DependencyObject o, object value)
{
o.SetValue(CompletedCommandParameterProperty, value);
}
public static object GetCompletedCommandParameter(DependencyObject o)
{
return o.GetValue(CompletedCommandParameterProperty);
}
private static void OnCompletedCommandChanged(object sender, DependencyPropertyChangedEventArgs e)
{
var sb = sender as Storyboard;
if (sb != null)
{
sb.Completed += (a, b) =>
{
var command = GetCompletedCommand(sb);
if (command != null)
{
if (command.CanExecute(GetCompletedCommandParameter(sb)))
{
command.Execute(GetCompletedCommandParameter(sb));
}
}
};
}
}
}