[英]Triggers aren't supported in Windows 8 XAML?
好的,如果 DataTriggers 在 Silverlight 和 Windows 8 中不再工作,誰能告訴我如何替換此功能?
例如;
在 ListView 或 GridView 中,如果某項的值為 x,
if x == "True"
StackPanel style= "MakeBackgroundGreen"
else
StackPanel style="MakeBackgroundRed"
有沒有辦法使用 XAML 和 C#(首選 C#,但任何語言都可以)在 Windows 8 metro 風格應用程序中創建類似的東西。
我聽說有人提到使用 VSM(Visual State 管理器),我該怎么做?
非常感謝。
您必須像這樣使用 Visual State 管理器:
<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>
之后,您可以像這樣以編程方式更改 state:
VisualStateManager.GoToState(this, "stateName", true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.