I was struggling with a "catastrophic failure" exception while working on a managed custom Windows 8 control and I've managed to localize the issue to a very simple test case. And now I'm stuck.
Say I have an enumeration defined like this:
public enum Modes
{
Mode1,
Mode2
}
Then I have a custom control with a dependency property defined like this
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));
And I try to switch the property from Mode1 to Mode2 via VisualState like this:
<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>
To do this I just call GoToState() when a button is clicked:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
VisualStateManager.GoToState(this, "VisualState", false);
}
And I get the infamous "Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"
I've tried to create exactly identical test case in Silverlight and it works just fine. Is this a Windows 8 XAML RC bug or am I doing something wrong?