Windows 10 UWP两个自适应触发器未按预期工作

时间:2016-09-02 10:36:46

标签: uwp-xaml

我有这个VisualStateGroups用于不同的屏幕分辨率。如果我将窗口从小到大调整大小,一切都按预期工作。但是,如果我将窗口从大到小调整大小,则第一个可视状态组被忽略,窗口布局将跳回到控件本身定义的那个。

<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
    <VisualState>
        <VisualState.StateTriggers>
            <!--VisualState to be triggered when window width is >= ??? effective pixels.-->
            <AdaptiveTrigger MinWindowWidth="720"></AdaptiveTrigger>
        </VisualState.StateTriggers>
        <VisualState.Setters>
            <Setter Target="labelFee.(RelativePanel.RightOf)" Value="labelAmount"/>
            <Setter Target="labelFee.(RelativePanel.Below)" Value="labelRate"/>
            <Setter Target="labelFee.Margin" Value="10,3,3,0"/>
            <Setter Target="labelLendingDate.(RelativePanel.RightOf)" Value="labelRemainingTime"/>
            <Setter Target="labelLendingDate.(RelativePanel.Below)" Value="labelAmount"/>
            <Setter Target="labelLendingDate.Margin" Value="10,3,3,0"/>
        </VisualState.Setters>
    </VisualState>
</VisualStateGroup>
<VisualStateGroup>
    <VisualState>
        <VisualState.StateTriggers>
            <!--VisualState to be triggered when window width is >= ??? effective pixels.-->
            <AdaptiveTrigger MinWindowWidth="900"></AdaptiveTrigger>
        </VisualState.StateTriggers>
        <VisualState.Setters>
            <Setter Target="labelFee.(RelativePanel.RightOf)" Value="labelAmount"/>
            <Setter Target="labelFee.(RelativePanel.Below)" Value="labelRate"/>
            <Setter Target="labelFee.Margin" Value="10,3,3,0"/>
            <Setter Target="labelRemainingTime.(RelativePanel.RightOf)" Value="labelFee"/>
            <Setter Target="labelRemainingTime.(RelativePanel.Below)" Value="labelRate"/>
            <Setter Target="labelRemainingTime.Margin" Value="10,3,3,0"/>
            <Setter Target="labelLendingDate.(RelativePanel.RightOf)" Value="labelRemainingTime"/>
            <Setter Target="labelLendingDate.(RelativePanel.Below)" Value="labelRate"/>
            <Setter Target="labelLendingDate.Margin" Value="10,3,3,0"/>
        </VisualState.Setters>
    </VisualState>
</VisualStateGroup>

1 个答案:

答案 0 :(得分:0)

对不起伙计我自己发现了。触发器需要在同一个VisualStateGroup元素中才能像我想要的那样工作。

<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
    <VisualState>
        <VisualState.StateTriggers>
            <!--VisualState to be triggered when window width is >= ??? effective pixels.-->
            <AdaptiveTrigger MinWindowWidth="720"></AdaptiveTrigger>
        </VisualState.StateTriggers>
        <VisualState.Setters>
            <Setter Target="labelFee.(RelativePanel.RightOf)" Value="labelAmount"/>
            <Setter Target="labelFee.(RelativePanel.Below)" Value="labelRate"/>
            <Setter Target="labelFee.Margin" Value="10,3,3,0"/>
            <Setter Target="labelLendingDate.(RelativePanel.RightOf)" Value="labelRemainingTime"/>
            <Setter Target="labelLendingDate.(RelativePanel.Below)" Value="labelAmount"/>
            <Setter Target="labelLendingDate.Margin" Value="10,3,3,0"/>
        </VisualState.Setters>
    </VisualState>
    <VisualState>
        <VisualState.StateTriggers>
            <!--VisualState to be triggered when window width is >= ??? effective pixels.-->
            <AdaptiveTrigger MinWindowWidth="900"></AdaptiveTrigger>
        </VisualState.StateTriggers>
        <VisualState.Setters>
            <Setter Target="labelFee.(RelativePanel.RightOf)" Value="labelAmount"/>
            <Setter Target="labelFee.(RelativePanel.Below)" Value="labelRate"/>
            <Setter Target="labelFee.Margin" Value="10,3,3,0"/>
            <Setter Target="labelRemainingTime.(RelativePanel.RightOf)" Value="labelFee"/>
            <Setter Target="labelRemainingTime.(RelativePanel.Below)" Value="labelRate"/>
            <Setter Target="labelRemainingTime.Margin" Value="10,3,3,0"/>
            <Setter Target="labelLendingDate.(RelativePanel.RightOf)" Value="labelRemainingTime"/>
            <Setter Target="labelLendingDate.(RelativePanel.Below)" Value="labelRate"/>
            <Setter Target="labelLendingDate.Margin" Value="10,3,3,0"/>
        </VisualState.Setters>
    </VisualState>
</VisualStateGroup>