0

我有 3 个视觉状态,带有自适应触发器。当窗户增加时,它们开火良好。但是,如果窗口从最大状态减小到较小状态,则设置器不起作用并且元素将它们的样式重置为默认值,就像它们没有视觉状态一样。

<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>
4

1 回答 1

0

缩小窗口时不触发视觉状态

问题是您将三个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>
于 2020-09-22T12:14:05.067 回答