Windows 8 XAML不支持触发器?

Dar*_*Zon 5 c# silverlight xaml silverlight-4.0 microsoft-metro

好的,如果DataTriggers在Silverlight和Windows 8中不再起作用,有人能告诉我如何替换这个功能吗?

例如;

在ListView或GridView中,如果项目的值为x,

if x == "True"
 StackPanel style= "MakeBackgroundGreen"
else
 StackPanel style="MakeBackgroundRed"
Run Code Online (Sandbox Code Playgroud)

有没有办法在Windows 8 metro风格的应用程序中使用XAML和C#创建类似的东西(首选C#,但任何语言都可以).

我听说有人提到使用VSM(Visual State Manager),我该怎么做?

非常感谢提前.

Amr*_*eda 2

您必须像这样使用视觉状态管理器:

   <VisualStateManager.VisualStateGroups>

        <!-- Visual states reflect the application's 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>
Run Code Online (Sandbox Code Playgroud)

之后,您可以像这样以编程方式更改状态:

        VisualStateManager.GoToState(this, "stateName", true);
Run Code Online (Sandbox Code Playgroud)