WPF 动画“无法冻结此 Storyboard 时间线树以供跨线程使用" [英] WPF Animation "Cannot freeze this Storyboard timeline tree for use across threads"

查看:178
本文介绍了WPF 动画“无法冻结此 Storyboard 时间线树以供跨线程使用"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个列表框,其所选项目绑定到我的 ViewModel 上的一个属性.每当所选项目不为空时,我想对其执行动画.但是,我不断收到以下错误无法冻结此 Storyboard 时间轴树以供跨线程使用",并且从研究中了解了为什么会发生这种情况.但是我不确定我需要采取什么方法来获得我想要的行为.

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>

推荐答案

你能发布你的故事板吗?听起来您在 Storyboard 定义中有某种绑定.

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

好吧,正如我怀疑的那样,这是因为您在 Storyboard 中使用了 Binding.您不能这样做,因为 WPF 试图冻结所有利用的资源通过效率模板以及当您在 Freezable,在本例中为 Storyboard,它可以防止它被冻结.

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.

这篇关于WPF 动画“无法冻结此 Storyboard 时间线树以供跨线程使用"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆