1
votes

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?

1
I've always found these "Catastrophic failure" events to be a gap in the WinRT framework, really unhelpful error. Have you tried having a standard storyboard within the visual state and launching with the Visual state manager (leaving in the target property), just change the vidual element Have you also tried it with a string as the dependancy property instead of an enum. Would test myself but my Win 8 machine is elsewhere at present. So much of Win 8 still feels like a Beta, expecialyl with the errors ;-( - Darkside
I've changed it to int for now and it works fine (except that it makes for an ugly API) - Alan Mendelevich

1 Answers

1
votes

Alan - this (custom Enums) isn't going to work for WinRT unfortunately.