canton7 / Stylet

A very lightweight but powerful ViewModel-First MVVM framework for WPF for .NET Framework and .NET Core, inspired by Caliburn.Micro.
MIT License
995 stars 144 forks source link

DoubleAnimation Completed Binding #196

Closed pedrollanes closed 3 years ago

pedrollanes commented 3 years ago

Is there any way to bind a storyboard completed event?

canton7 commented 3 years ago

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)

pedrollanes commented 3 years ago

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

canton7 commented 3 years ago

What error did you get, exactly?

pedrollanes commented 3 years ago

With this code `

` 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.'
canton7 commented 3 years ago

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.

canton7 commented 3 years ago

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?

pedrollanes commented 3 years ago

OK, this afternoon I'll see and I tell you.

pedrollanes commented 3 years ago

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

canton7 commented 3 years ago

Can you post a repro, please? That's not enough information for me to tell what's happening.

pedrollanes commented 3 years ago

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.

canton7 commented 3 years ago

Ah yeah, it will struggle to find the VM from a ResourceDictionary