在使用托管自定义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错误还是我做错了什么?
答案 0 :(得分:1)
Alan - 不幸的是,这个(自定义枚举)对WinRT不起作用。