locked
VisualStateManager Storyboard TargetName should be checked

    Question

  • I would like to provide a feedback for VS2012 Update 2 CTP. I think one of the most common failures of Windows Store apps certification is crash related to snap view. It is often caused by removing or renaming of XAML elements, which still preservs in the VisualStateManager.

    For example this causes a runtime crash when backButton element does not exists:

    <VisualStateManager.VisualStateGroups>
    
        <!-- Visual states reflect the application's view state -->
        <VisualStateGroup x:Name="ApplicationViewStates">
            <VisualState x:Name="FullScreenLandscape"/>
            <VisualState x:Name="Filled"/>
    
            <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
            <VisualState x:Name="FullScreenPortrait">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
    
            <!-- The back button and title have different styles when snapped -->
            <VisualState x:Name="Snapped">
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

    I think Visual Studio should check if elements names mentioned in Storyboard.TargetName really exists. If not, it should cause a compile time error. Runtime error is too late for this.

    Tuesday, March 26, 2013 8:20 AM

Answers

  • Hi,

        Thanks for the feedback. In Blend if you delete an element we do a referential integrity check and remove all associated storyboards in scope (including in states) that refer the element, so you wouldn't run into this issue. This is feedback is very valid for Visual Studio and I will definitely take this back to my team.

    Regards

    Harikrishna Menon

    Program Manager

    XAML Tools Team


    Dev@Mic

    Thursday, March 28, 2013 6:59 PM

All replies