"Can't Freeze BeginStoryboard.Storyboard" when using an attached property.
I'm using the code here that allows me to use a command for a storyboard's Completed event.
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!).
Code: Select all
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) =>
{
Code: Select all
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard local:StoryboardHelper.CompletedCommand="{Binding CompletedFinishedCommand}">
...
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.
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?
In the meantime, have you tried interactivity triggers and actions?
Code: Select all
<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>
Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.
I made the issue, and I'll try the triggers thanks!
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.
Thanks for the report.
Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.
Can I do this without the storyboard being a resource? I seem to get the same error message.
"Can't Freeze BeginStoryboard.Storyboard"
Code: Select all
<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>
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.
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:
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:
Code: Select all
<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>
Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.
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.
Code: Select all
<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>
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.
To make sure the StoryboardCompletedTrigger is being executed, could you please add another action to the trigger, something like
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:
Code: Select all
<ei:ChangePropertyAction PropertyName="Height" Value="30" TargetName="SomeElement"/>
I made the following test in xamltoy and it works as expected, so I have to be missing something:
Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.
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:
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.
Here is the entire DataTemplate:
Code: Select all
<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>
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: "Can't Freeze BeginStoryboard.Storyboard" when using an attached property.
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.
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: Ahrefs [Bot] and 15 guests