减少 window 时视觉状态不触发

Visual state not firing when reducing window

我有 3 种视觉状态,带有自适应触发。当 windows 增加时,他们开火很好。但是,如果 window 从 biggest 状态减少到 smaller ,setters 不工作并且元素将它们的样式重置为默认状态,就像它们没有视觉状态一样。

<Grid x:Name="mainGrid" Style="{StaticResource mainGridStyle}">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="largeSize">
                <VisualState>
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="1520"/>
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="mainGrid.Background" Value="{StaticResource lgBrush}"/>
                        <Setter Target="LogoImage.Style" Value="{StaticResource lgLogoStyle}"/>
                        <Setter Target="TxbClienForStreaming.FontSize" Value="60"/>
                        <Setter Target="TxbAddText.FontSize" Value="42"/>
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="mediumSize">
                <VisualState>
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="600"/>
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="mainGrid.Background" Value="{StaticResource mdBrush}"/>
                        <Setter Target="LogoImage.Style" Value="{StaticResource mdLogoStyle}"/>
                        <Setter Target="TxbClienForStreaming.FontSize" Value="45"/>
                        <Setter Target="TxbAddText.FontSize" Value="28"/>
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="smallSize">
                <VisualState>
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="0"/>
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Target="mainGrid.Background" Value="{StaticResource smBrush}"/>
                        <Setter Target="TxbClienForStreaming.FontSize" Value="36"/>
                        <Setter Target="TxbAddText.FontSize" Value="24"/>
                        <Setter Target="BtnGetNow.FontSize" Value="34"/>
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

Visual state not firing when reducing window

问题是你把三个VisualState放在了不同的组里,请像下面这样把三个VisualState合到一个组里。

<VisualStateManager.VisualStateGroups>
    <VisualStateGroup>
        <VisualState x:Name="smallSize">
            <VisualState.StateTriggers>
                <AdaptiveTrigger MinWindowWidth="0" />
            </VisualState.StateTriggers>
            <VisualState.Setters>
                <Setter Target="mainGrid.Background" Value="Red" />
            </VisualState.Setters>
        </VisualState>
        <VisualState x:Name="mediumSize">
            <VisualState.StateTriggers>
                <AdaptiveTrigger MinWindowWidth="665" />
            </VisualState.StateTriggers>
            <VisualState.Setters>
                <Setter Target="mainGrid.Background" Value="Green" />
            </VisualState.Setters>
        </VisualState>
        <VisualState x:Name="largeSize">
            <VisualState.StateTriggers>
                <AdaptiveTrigger MinWindowWidth="1520" />
            </VisualState.StateTriggers>
            <VisualState.Setters>
                <Setter Target="mainGrid.Background" Value="Blue" />
            </VisualState.Setters>
        </VisualState>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>