DoubleAnimation Completed Binding
pedrollanes opened this issue · comments
Is there any way to bind a storyboard completed event?
Looks like a normal event: have you tried using an action with it?
(In future, please open questions as discussions. GitHub have removed the helpful button letting me turn issues into discussions however annoyingly)
Sorry I will do it in the future.
I tried to use action but I recieved an error. I think that is an special event and a normal binding action doesn't work
What error did you get, exactly?
With this code
<Trigger Property="Visibility" Value="Visible"> <Trigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Completed="{s:Action Check}" Storyboard.TargetProperty="Opacity" From="0.0" To="1.0" Duration="0:0:2.5" /> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> </Trigger>
and viewmodel action:
public Task Check() { var a = 0; return Task.CompletedTask; }
Error
Stylet.Xaml.ActionNotSetException: 'View.ActionTarget not set on control System.Windows.Media.Animation.DoubleAnimation (method Check). This probably means the control hasn't inherited it from a parent, e.g. because a ContextMenu or Popup sits in the visual tree. You will need so set 's:View.ActionTarget' explicitly. See the wiki section "Actions" for more details.'
Aah, so it can't find the ActionTarget. It should have been able to get something from IRootObjectProvider
, but it seems not in this case. I'll have to look at why WPF is behaving that way. You can follow the instructions, and set s:View.ActionTarget
to your ViewModel.
I just tried to reproduce this and failed. From Stylet.Samples.Hello, I replaced the Button
with:
<Button Command="{s:Action SayHello}" Content="SayHello" Visibility="{Binding CanSayHello, Converter={x:Static s:BoolToVisibilityConverter.Instance}}">
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<Trigger Property="Visibility" Value="Visible">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Completed="{s:Action Check}" Storyboard.TargetProperty="Opacity" From="0.0" To="1.0" Duration="0:0:2.5" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
and add public void Check() { }
to the VM. The animation works, and Check
is correctly invoked at the end.
Please could you add a full repro?
OK, this afternoon I'll see and I tell you.
Ok I have inserted all content into a button and it works. But if i use in a grid doesn't work. I suppose its right. Thanks
Can you post a repro, please? That's not enough information for me to tell what's happening.
Ok the problem is that I was putting trigger in a style of a resource dictionary. When I put all the style in the button I have no problem.
Ah yeah, it will struggle to find the VM from a ResourceDictionary