3

以前は、Visual Studio 2012 の Windows 8.0 アプリに対して非常に優れたデザイナー サポートがありました。デバイス パネルVisualStatesでは、ページ内の別の に移動できVisualStateManager.VisualStateGroups、設計時に適切なプロパティが更新されます。

8.1 では、 は特定のスナップされたレイアウトに基づくものでVisualStateはなくなりましたが、引き続き を使用し、画面に基づいて更新することができます。VisualStateManagerwidth

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>

これが設計時のビューです: (不正解)

デザイン

これは実行時のビューです:(正しい)

ランタイム

4

0 に答える 0