Triggers not supported in Windows 8 XAML?

Well, if DataTriggers no longer works in Silverlight and Windows 8, can someone tell me how to replace this feature?

For instance:

In a ListView or GridView element, if the element has an x ​​value,

if x == "True"
 StackPanel style= "MakeBackgroundGreen"
else
 StackPanel style="MakeBackgroundRed"

Is there a way to create something similar in Metro style in Windows 8 style using XAML and C # (preferred C #, but any language will do).

I heard some people mention using VSM (Visual State Manager), how can I do this?

Thank you very much in advance.

+5
source share
1 answer

You will need to use Visual State Manager as follows:

   <VisualStateManager.VisualStateGroups>

        <!-- Visual states reflect the application view state -->
        <VisualStateGroup>
            <VisualState x:Name="FullScreenLandscape"/>
            <VisualState x:Name="Filled"/>

            <!-- The back button 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>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                        <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                    </ObjectAnimationUsingKeyFrames>

                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

after that you can change the state programmatically as follows:

        VisualStateManager.GoToState(this, "stateName", true);
+2
source

All Articles