如何在Windows 8.1 XAML应用程序中获得VisualStateGroups的Designer支持

时间:2013-11-11 23:58:14

标签: .net vb.net winrt-xaml visual-studio-2013 visual-studio-designer

在Visual Studio 2012中,Windows 8.0应用程序曾经有过非常棒的设计器支持。在Device Panel中,您可以移动到页面上VisualStates内的不同VisualStateManager.VisualStateGroups将在设计时更新适当的属性。

在8.1中,VisualStateno longer based on specific snapped layouts,但您仍然可以使用VisualStateManager并根据屏幕width进行更新。

Q :如何在设计时更新这些更改?


这是一个在运行时工作的变化的简单示例,但不是设计时。

MainView.xaml.vb

Private Sub MainView_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
    AddHandler Me.SizeChanged, AddressOf WindowSizeChanged
    ApplyViewState(Me.Width, Me.Height)
End Sub

Private Sub WindowSizeChanged(sender As Object, e As SizeChangedEventArgs)
    ApplyViewState(e.NewSize.Width, e.NewSize.Height)
End Sub

Private Sub ApplyViewState(ByVal viewWidth As Double, ByVal viewHeight As Double)
    If viewWidth < 350 Then
        VisualStateManager.GoToState(Me, "SmallLayout", True)
    Else
        VisualStateManager.GoToState(Me, "RegularLayout", True)
    End If
End Sub

MainView.xaml

<Page x:Name="PageRoot"
    x:Class="WinStoreMvvmTemplate.View.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Grid Background="Red" x:Name="ContentGrid">

        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState x:Name="RegularLayout"/>
                <VisualState x:Name="SmallLayout">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames 
                            Storyboard.TargetName="ContentGrid"
                            Storyboard.TargetProperty="Background">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Blue"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

    </Grid>
</Page>

以下是设计时的视图:(不正确)

design

以下是运行时的视图:(正确)

runtime

0 个答案:

没有答案