无法在不可变对象上设置动画(0)。(1)? [英] Cannot animate (0).(1) on an immutable object?

查看:562
本文介绍了无法在不可变对象上设置动画(0)。(1)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有编写的自定义主题的ComboBox,并且收到错误消息无法在不可变对象上设置(0)。(1)的动画。当用户在组合框中选择一个选项后,设置其 selectedindex 时,就会发生这种情况。

I have a ComboBox with a custom theme I wrote, and I get the error message "Cannot animate (0).(1) on an immutable object." This specifically happens when I set its selectedindex after the user selects one of the options in the combobox.

在线研究发现,这是数据绑定项或动态资源的常见问题。我没有使用任何数据绑定资源,但是我认为正在发生的事情是因为组合框已折叠,它会尝试设置一个不存在的按钮的状态。我将其范围缩小为以下代码:

Doing some research online, I found that this is a common issue with databound items or dynamic resources. I'm not using any databound resources, but what I think is happening is since the combobox is collapsed, it tries to set the state of a button that doesn't exist. I narrowed it down to this code:

<ControlTemplate.Triggers>
  <Trigger Property="IsSelected" Value="True">
     <Setter TargetName="Border" Property="Background" Value="{DynamicResource spPressedStateBrush}" />
  </Trigger>
  <Trigger Property="IsMouseOver" Value="True">
     <Setter TargetName="Border" Property="Background" Value="{DynamicResource spOverStateBrush}" />
  </Trigger>
</ControlTemplate.Triggers>

这取决于以下动态资源:

Which depends on these Dynamic Resources:

<LinearGradientBrush x:Key="spOverStateBrush" StartPoint="0,0" EndPoint="0,1">
    <GradientStop Color="#2C8CBF" Offset="0" />
    <GradientStop Color="#2793BF" Offset="0.5" />
    <GradientStop Color="#2483BF" Offset="0.5001" />
    <GradientStop Color="#2C8CBF" Offset="1" />
</LinearGradientBrush>

<LinearGradientBrush x:Key="spPressedStateBrush" StartPoint="0,0" EndPoint="0,1">
    <GradientStop Color="#0C6C9F" Offset="0" />
    <GradientStop Color="#07739F" Offset="0.5" />
    <GradientStop Color="#04639F" Offset="0.5001" />
    <GradientStop Color="#0C6C9F" Offset="1" />
</LinearGradientBrush>

所以我很确定那些动态资源是罪魁祸首,但是我该如何解决这个问题呢?

So I'm pretty sure those dynamic resources are the culprit, but how would I solve this problem?

推荐答案

通过比较代码与原始控件模板,我发现将控件使用的所有资源都传输到文件中本身,并用 StaticResources 替换所有 DynamicResources 并修复了我遇到的错误。

After painstakingly trying to debug it by comparing the code to the original Control Template, I figured out that transporting all of the resources that my control uses into the file itself, and replacing all DynamicResources with StaticResources and that fixed the bug I was having.

这篇关于无法在不可变对象上设置动画(0)。(1)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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