VisualState AdaptiveTrigger 未触发

VisualState AdaptiveTrigger not firing

我观看了 BUILD 活动中的会话 "From the Small Screen to the Big Screen: Building Universal Windows App Experiences with XAML"。 http://channel9.msdn.com/Events/Build/2015/2-679

我想尝试 AdaptiveTrigger,但我的最小 Windows 10 UWP 应用程序无法启动它。

<VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="WindowSizeStates">
        <VisualState x:Name="WideState">
            <VisualState.StateTriggers>
                <AdaptiveTrigger MinWindowWidth="800"/>
            </VisualState.StateTriggers>
            <VisualState.Setters>
                <Setter Target="rect.Fill" Value="Beige" />
            </VisualState.Setters>
        </VisualState>
        <VisualState x:Name="NarrowState">
            <VisualState.StateTriggers>
                <AdaptiveTrigger MinWindowWidth="0" />
            </VisualState.StateTriggers>
            <VisualState.Setters>
                <Setter Target="rect.Fill" Value="White" />
            </VisualState.Setters>
        </VisualState>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <RelativePanel>
        <Rectangle x:Name="rect" Width="100" Height="100" RelativePanel.AlignTopWithPanel="True" Fill="Beige"/>
    </RelativePanel>
</Grid>

但是没有任何反应。似乎触发器根本没有被触发。我错过了什么吗?

此致!

是的,当您将组放在页面中而不是放在第一个控件中时,就会发生这种情况。尝试放入:

<Grid...>
   <VisualStateManager.VisualStateGroups>

</Grid>

另外如果你想制作更复杂的自适应触发器我在这里写了一篇文章:codeproject advanced view states