.NET MAUI 自适应触发器不触发

问题描述 投票:0回答:0

我在新文件中设置了一个样式,该文件正在合并到

App.xaml
中。在视图中,Intellisense 向我展示了我想要使用的样式的
x:Key
,但自适应触发器不会触发。我使用仅包含用于更改背景颜色的设置器的样式对其进行了测试。这很好用。只是不是自适应触发器。

我正在尝试将此样式应用于所有元素(

<ContentPage>
的子元素)的父容器(网格),但即使在内部控件上使用此样式,问题仍然存在。我也尝试更改 TargetType,但即使在其他控件类型上它也不起作用。

我什至尝试将样式放在控件和相同的视图页面中,但它也不是那样工作的。我不知道我做错了什么。

因为这个应用程序会有很多页面,我更希望能够使用一个单独的文件来包含样式,以便将来在中心位置进行更改。

在 Windows 和多个 Android 模拟器上测试。

当前值用于测试。 风格:

    <Style x:Key="MainGridStyle"
       TargetType="Grid">
    <Setter Property="VisualStateManager.VisualStateGroups">
        <VisualStateGroupList>
            <VisualStateGroup>
                <VisualState x:Name="Small">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="0"/>
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Property="WidthRequest" Value="200"/>
                    </VisualState.Setters>

                </VisualState>
                <VisualState x:Name="Medium">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="800"/>
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                        <Setter Property="WidthRequest" Value="500"/>
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateGroupList>

    </Setter>

</Style>

App.xaml

    <Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources/Styles/Colors.xaml" />
            <ResourceDictionary Source="Resources/Styles/Styles.xaml" />
            <ResourceDictionary Source="Resources/Styles/CustomStyles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

控制开始标签(我也尝试了 StaticResource,结果相同):

    <Grid
    Style="{DynamicResource MainGridStyle}">
.net xaml maui visualstatemanager adaptive-trigger
© www.soinside.com 2019 - 2024. All rights reserved.