我为Windows RT设计了一个应用程序。我使用 VisualStateManager
来捕捉用户控件。但是当我的应用程序崩溃时,用户控件没有改变。问题出在哪里?
<Grid Width="500" Height="40" Margin="15" x:Name="questionRoot" Background="DarkSeaGreen">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
<TextBlock x:Name="OrginalWord" FontSize="32" Text="{Binding Question.OrginalWord}"></TextBlock>
</StackPanel>
<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"/>
<!--
The back button and title have different styles when snapped, and the list representation is substituted
for the grid displayed in all other view states
-->
<VisualState x:Name="Snapped">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="OrginalWord" Storyboard.TargetProperty="FontSize">
<DiscreteObjectKeyFrame KeyTime="0" Value="88"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
最佳答案
您是否在代码隐藏中调用 VisualStateManager.GoToState
方法?您需要检测应用程序何时从 Full/Fill 转换到 Snap 模式,然后调用此方法。
您将找到此函数的 MSDN 文档 here .
当 Page
父控件或应用程序 Window
的大小发生变化时,您通常会识别出此转换。 This SO question (查看 Jowen 的答案)为您提供了一个代码片段,说明如何通过监听窗口大小更改事件来执行此操作。
关于c# - 用户控件中的 VisualStateManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13717968/