【问题标题】:"Catastrophic failure" when trying to animate custom enum dependency property尝试为自定义枚举依赖属性设置动画时出现“灾难性失败”
【发布时间】:2012-07-25 10:59:24
【问题描述】:

我在处理托管的自定义 Windows 8 控件时遇到了“灾难性故障”异常,我已设法将问题本地化为一个非常简单的测试用例。现在我被困住了。

假设我有一个这样定义的枚举:

public enum Modes
{
  Mode1,
  Mode2
}

然后我有一个自定义控件,其依赖属性定义如下

public Modes Mode
{
    get { return (Modes)GetValue(ModeProperty); }
    set { SetValue(ModeProperty, value); }
}

// Using a DependencyProperty as the backing store for Mode.  This enables animation, styling, binding, etc...
public static readonly DependencyProperty ModeProperty =
    DependencyProperty.Register("Mode", typeof(Modes), typeof(CustomControl1), new PropertyMetadata(Modes.Mode1));

我尝试通过 VisualState 将属性从 Mode1 切换到 Mode2,如下所示:

<VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="VisualStateGroup">
        <VisualState x:Name="VisualState">
            <Storyboard>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(CustomControl1.Mode)" Storyboard.TargetName="customControl1">
                    <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                            <local:Modes>Mode2</local:Modes>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
        </VisualState>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

为此,我只需在单击按钮时调用 GoToState():

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    VisualStateManager.GoToState(this, "VisualState", false);
}

我得到了臭名昭著的“灾难性故障(HRESULT 异常:0x8000FFFF (E_UNEXPECTED))”

我尝试在 Silverlight 中创建完全相同的测试用例,并且效果很好。这是 Windows 8 XAML RC 错误还是我做错了什么?

【问题讨论】:

  • 我一直发现这些“灾难性故障”事件是WinRT框架中的一个漏洞,真的是无益的错误。您是否尝试过在可视状态中使用标准情节提要并使用可视状态管理器启动(保留在目标属性中),只需更改 vidual 元素您是否也尝试过使用字符串作为依赖属性而不是枚举。会测试自己,但我的 Win 8 机器目前在别处。 Win 8 的大部分内容仍然感觉像是一个 Beta,特别是有错误;-(
  • 我现在已经把它改成了 int 并且它工作正常(除了它会导致一个丑陋的 API)

标签: xaml windows-8 winrt-xaml


【解决方案1】:

Alan - 不幸的是,这个(自定义枚举)不适用于 WinRT。

【讨论】:

  • 哎哟。你的意思是即使在最终版本中也没有?你会推荐使用什么来代替? int 工作正常,但完全与上下文无关,字符串很乱。还有其他选择吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-30
  • 2013-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-13
相关资源
最近更新 更多