UWP:创建自定义文件名限定符无效

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

我一直在尝试创建一组custom文件名限定符,以便能够根据屏幕方向加载不同的视图(XAML)。

按照Microsoft文档中的说明:https://docs.microsoft.com/en-us/windows/uwp/app-resources/tailor-resources-lang-scale-contrast,我已经设置了以下限定符:

switch (orientation)
            {
                case EnumScreenOrientation.Landscape:
                    ResourceContext.SetGlobalQualifierValue("Orientation", "Landscape", ResourceQualifierPersistence.LocalMachine);
                    break;
                case EnumScreenOrientation.Portrait:
                    ResourceContext.SetGlobalQualifierValue("Orientation", "Portrait", ResourceQualifierPersistence.LocalMachine);
                    break;
                default:
                    ResourceContext.SetGlobalQualifierValue("Orientation", "Landscape", ResourceQualifierPersistence.LocalMachine);
                    break;
            }

然后在类似这样的项目中使用它:MainPage.Orientation-Portrait.xamlMainPage.Orientation-Landscape.xaml,而默认视图称为MainPage.xaml。

我还尝试将xamls放置在名为Orientation-Portrait和Orientation-Landscape的各个文件夹中。没有效果。视图从不显示。

我已经尝试使用Scale-125和Scale-150限定符,并且该机制正在起作用。

有任何建议/提示吗?

c# xaml uwp uwp-xaml screen-orientation
1个回答
0
投票

同时解决了它:

ResourceContext.SetGlobalQualifierValue(...)只能覆盖现有的限定符。因此,如果您这样做:

ResourceContext.SetGlobalQualifierValue("Custom", "Orientation-Landscape", ResourceQualifierPersistence.LocalMachine);

并将文件名设置为:MainPage.Custom-Orientation-Ladscape,一切将按预期工作。

© www.soinside.com 2019 - 2024. All rights reserved.