asusralis
Topic Author
Posts: 85
Joined: 30 Jul 2018, 05:03

"Can't Freeze BeginStoryboard.Storyboard" when using an attached property.

16 Jun 2020, 21:38

I'm using the code here that allows me to use a command for a storyboard's Completed event.
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) =>
            {

  <DataTrigger.EnterActions>
                                                        <BeginStoryboard>
                                                            <Storyboard local:StoryboardHelper.CompletedCommand="{Binding CompletedFinishedCommand}">
                                                                ...
                                                            </Storyboard>
                                                        </BeginStoryboard>
                                                    </DataTrigger.EnterActions>
However, when I try to use it with Noesis I get: "Can't Freeze BeginStoryboard.Storyboard" The storyboard plays but the command does not execute. If this is not possible with Noesis for some reason, is there a workaround? I can't use the Completed event in the code-behind because, from what I can tell, it doesn't give access to the particular data context and this storyboard is being used in an ItemsControl (I need the particular vm!).
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.

18 Jun 2020, 12:58

If this works in Blend then is a bug in Noesis, could you please open a ticket in our bugtracker?

In the meantime, have you tried interactivity triggers and actions?
<i:Interaction.Triggers>
  <ei:DataTrigger Binding="..." Value="...">
    <ei:ControlStoryboardAction Storyboard="{StaticResource SomeAnimation}"/>
  </ei:DataTrigger>
  <ei:StoryboardCompletedTrigger Storyboard="{StaticResource SomeAnimation}">
    <i:InvokeCommandAction Command="{Binding CompletedFinishedCommand}"/>
  </ei:StoryboardCompletedTrigger>
</i:Interaction.Triggers>
 
asusralis
Topic Author
Posts: 85
Joined: 30 Jul 2018, 05:03

Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.

21 Jun 2020, 19:26

I made the issue, and I'll try the triggers thanks!
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.

22 Jun 2020, 11:09

Thanks for the report.
 
asusralis
Topic Author
Posts: 85
Joined: 30 Jul 2018, 05:03

Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.

22 Jun 2020, 18:12

Can I do this without the storyboard being a resource? I seem to get the same error message.
<DataTrigger.EnterActions>
                                                        <BeginStoryboard>
                                                            <Storyboard>
                                                                <i:Interaction.Triggers>
                                                                    <ei:StoryboardCompletedTrigger>
                                                                        <i:InvokeCommandAction Command="{Binding CompletedFinishedCommand}" />
                                                                    </ei:StoryboardCompletedTrigger>
                                                                </i:Interaction.Triggers>
                                                                <ColorAnimation
                                                                    FillBehavior="HoldEnd"
                                                                    Storyboard.TargetProperty="(StackPanel.Background).(SolidColorBrush.Color)"
                                                                    To="DodgerBlue"
                                                                    Duration="0:0:0.5" />
                                                                <DoubleAnimation
                                                                    BeginTime="0:0:1.5"
                                                                    Storyboard.TargetProperty="LayoutTransform.(ScaleTransform.ScaleY)"
                                                                    To="0"
                                                                    Duration="0:0:00.5" />
                                                            </Storyboard>
                                                        </BeginStoryboard>
                                                    </DataTrigger.EnterActions>
"Can't Freeze BeginStoryboard.Storyboard"
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.

22 Jun 2020, 19:01

No, you shouldn't mix BeginStoryboard with interactivity actions.

Anyway, I've been doing some tests and this is not allowed either in WPF (see following xaml). The error comes from having bindings inside the BeginStoryboard:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid.Resources>
    <ControlTemplate x:Key="Test" TargetType="Control">
      <Grid Background="Silver"/>
      <ControlTemplate.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
          <Trigger.EnterActions>
            <BeginStoryboard>
              <Storyboard Storyboard.TargetName="{Binding Name}">
                <DoubleAnimation To="100" Storyboard.TargetProperty="Width"/>
              </Storyboard>
            </BeginStoryboard>
          </Trigger.EnterActions>
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
  </Grid.Resources>
  <Control Template="{StaticResource Test}"/>
</Grid>
 
asusralis
Topic Author
Posts: 85
Joined: 30 Jul 2018, 05:03

Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.

23 Jun 2020, 20:52

Is it supposed to be like this? It is not giving me the error message anymore, and the animation is still playing, but I'm just not getting the CompletedFinishedCommand invoked. I'm certain it's binding correctly as the other properties are, and I've double checked the spelling.
                                    <StackPanel.Resources>
                                        <Storyboard x:Key="CompletedStoryboard">
                                            ...
                                    </StackPanel.Resources>
                                    <i:Interaction.Triggers>
                                        <ei:DataTrigger Binding="{Binding Completed}" Value="True">
                                            <ei:ControlStoryboardAction Storyboard="{StaticResource CompletedStoryboard}" />
                                        </ei:DataTrigger>
                                        <ei:StoryboardCompletedTrigger Storyboard="{StaticResource CompletedStoryboard}">
                                            <i:InvokeCommandAction Command="{Binding CompletedFinishedCommand}" />
                                        </ei:StoryboardCompletedTrigger>
                                    </i:Interaction.Triggers>
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.

24 Jun 2020, 11:22

To make sure the StoryboardCompletedTrigger is being executed, could you please add another action to the trigger, something like
<ei:ChangePropertyAction PropertyName="Height" Value="30" TargetName="SomeElement"/>
Are both Completed and CompletedFinishedCommand properties exposed by the same ViewModel?

I made the following test in xamltoy and it works as expected, so I have to be missing something:

 
asusralis
Topic Author
Posts: 85
Joined: 30 Jul 2018, 05:03

Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.

25 Jun 2020, 22:47

It doesn't seem like anything is happening in the StoryboardCompletedTrigger. Even putting a wrong TargetType (I would assume it would give an error) does nothing. I did remove the scale animation to test the height.

Here is the entire DataTemplate:
                            <DataTemplate>
                                <StackPanel x:Name="WishRoot" Background="Transparent">
                                    <StackPanel.LayoutTransform>
                                        <ScaleTransform ScaleY="1" />
                                    </StackPanel.LayoutTransform>
                                    <StackPanel.Resources>
                                        <Storyboard x:Key="CompletedStoryboard">
                                            <ColorAnimation
                                                FillBehavior="HoldEnd"
                                                Storyboard.TargetProperty="(StackPanel.Background).(SolidColorBrush.Color)"
                                                To="DodgerBlue"
                                                Duration="0:0:0.5" />
                                            <DoubleAnimation
                                                BeginTime="0:0:1.5"
                                                Storyboard.TargetProperty="LayoutTransform.(ScaleTransform.ScaleY)"
                                                To="0"
                                                Duration="0:0:00.5" />
                                        </Storyboard>
                                    </StackPanel.Resources>
                                    <i:Interaction.Triggers>
                                        <ei:DataTrigger Binding="{Binding Completed}" Value="True">
                                            <ei:ControlStoryboardAction Storyboard="{StaticResource CompletedStoryboard}" />
                                        </ei:DataTrigger>
                                        <ei:StoryboardCompletedTrigger Storyboard="{StaticResource CompletedStoryboard}">
                                            <i:InvokeCommandAction Command="{Binding CompletedFinishedCommand}" />
                                            <ei:ChangePropertyAction
                                                PropertyName="Height"
                                                TargetName="WishRoot"
                                                Value="30" />
                                        </ei:StoryboardCompletedTrigger>
                                    </i:Interaction.Triggers>
                                    <StackPanel.Style>
                                        <Style TargetType="StackPanel">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding PositiveProgress}" Value="True">
                                                    <DataTrigger.EnterActions>
                                                        <BeginStoryboard>
                                                            <Storyboard>
                                                                <ColorAnimation
                                                                    AutoReverse="True"
                                                                    FillBehavior="Stop"
                                                                    Storyboard.TargetProperty="(StackPanel.Background).(SolidColorBrush.Color)"
                                                                    To="Green"
                                                                    Duration="0:0:0.5" />
                                                            </Storyboard>
                                                        </BeginStoryboard>
                                                    </DataTrigger.EnterActions>
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding PositiveProgress}" Value="False">
                                                    <DataTrigger.EnterActions>
                                                        <BeginStoryboard>
                                                            <Storyboard>
                                                                <ColorAnimation
                                                                    AutoReverse="True"
                                                                    FillBehavior="Stop"
                                                                    Storyboard.TargetProperty="(StackPanel.Background).(SolidColorBrush.Color)"
                                                                    To="Red"
                                                                    Duration="0:0:0.5" />
                                                            </Storyboard>
                                                        </BeginStoryboard>
                                                    </DataTrigger.EnterActions>
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </StackPanel.Style>
                                    <TextBlock
                                        FontSize="{StaticResource FontSize.Large}"
                                        FontWeight="Bold"
                                        Text="{Binding Wish.Name}" />
                                    <TextBlock
                                        Margin="0,-5,0,0"
                                        Text="{Binding Wish.Description}"
                                        TextWrapping="Wrap" />
                                </StackPanel>
                            </DataTemplate>
Yes, they are on the same viewmodel. From what I can tell, it seems the StoryboardCompletedAction is not being called at all. Sorry this is taking so much of your time :( I'm not exactly how to troubleshoot this.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.

26 Jun 2020, 14:10

It is very strange because I just took your data template to xamltoy, simplified to something I can use without code-behind, and the storyboard plays fine triggering the completed action at the end.



Perhaps you can start from the same commented xaml, make sure it works, and start changing things until it stops working.
Please let me know if at least it worked with my changes in your game.

Who is online

Users browsing this forum: Google [Bot] and 1 guest