c# - 用户控件中的 VisualStateManager

标签 c# wpf silverlight windows-store-apps

我为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/

相关文章:

c# - VSTO 备选方案

c# - 无法让 TextBlock 在 ListBox 内自动换行

c# - 在 Windows Phone silverlight 8.1 上接收 WNS 推送通知

c# - "x.Groups = list"有效但 "x.Groups.Add(listItem)"抛出空引用异常?

c# - 自定义页面过滤器中的 ASP .NET Core 注入(inject)服务

c# - 使用 LINQ 对备用对进行分组

wpf - 如何同步ListCollectionView.CurrentItem和ListView.SelectedItem?

c# - 从 View 模型的构造函数调用异步方法

.net - 关于在 WPF 中调试焦点问题的任何提示?

silverlight - Silverlight插件在视频 session 中崩溃