Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Animation "Cannot freeze this Storyboard timeline tree for use across threads"

I currently have a listbox that has its selected item bound to a property on my ViewModel. Whenever the selected item isn't null I want to perform an animation on it. However I keep getting the following error "Cannot freeze this Storyboard timeline tree for use across threads" and from research sort of understand why this is happening. However I am unsure of what approach I need to take to get the behavior I want.

<Storyboard x:Key="ShowItemEdit">
    <DoubleAnimation
        Storyboard.TargetName="lstItemList"
        Storyboard.TargetProperty="ListBox.Width"
        To="{Binding ActualWidth, ElementName=UserControl}"
        Duration="0:0:0.40" />
    ...
</Storyboard>

<Style x:Key="ListStyle">
    <Style.Triggers>
        <DataTrigger Binding="{Binding SelectedItem, Converter={StaticResource IsNullConverter}}" Value="False">
            <DataTrigger.EnterActions>
            <BeginStoryboard Storyboard="{StaticResource ShowItemEdit}" />
        </DataTrigger.EnterActions>
        </DataTrigger>
     </Style.Triggers>
</Style>

<ListBox x:Name="lstItemList" Style={StaticResource ListStyle}" SelectedItem="{Binding SelectedItem}">
    ...
</ListBox>
like image 620
jwarzech Avatar asked Nov 03 '09 19:11

jwarzech


3 Answers

Can you post your Storyboard? It sounds like you have some kind of Binding in the Storyboard definition.


Ok so, as I suspected, it's because you're using a Binding in your Storyboard. You can't do this because WPF attempts to freeze all the resources leveraged by a template for efficiency and when you use a Binding on a Freezable, in this case the Storyboard, it prevents it from being able to be frozen.

like image 197
Drew Marsh Avatar answered Nov 17 '22 05:11

Drew Marsh


There is a technique that you can use to get around the Freezable issue that allows you to use a binding for the "To" value of your animation (rather than hard-coding a value there). Its pretty straightforward and I've outlined it here.

like image 34
Jason Frank Avatar answered Nov 17 '22 04:11

Jason Frank


Old question but might be useful for other people. Sometimes creating the Storyboard in the code-behind can be simpler: https://stackoverflow.com/a/10848781/779521

like image 3
Sverrir Sigmundarson Avatar answered Nov 17 '22 04:11

Sverrir Sigmundarson