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

C# UWP:创建自定义文件名限定符无效,c#,xaml,uwp,uwp-xaml,screen-orientation,C#,Xaml,Uwp,Uwp Xaml,Screen Orientation,我一直在尝试创建一组自定义文件名限定符,以便能够根据屏幕方向加载不同的视图(XAML) Microsoft文档中有以下说明:,我已设置了以下限定符: switch (orientation) { case EnumScreenOrientation.Landscape: ResourceContext.SetGlobalQualifierValue("Orientation", "Landscape"

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

Microsoft文档中有以下说明:,我已设置了以下限定符:

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-grait.xamlMainPage.Orientation-scanner.xaml,而默认视图称为MainPage.xaml

我还尝试将XAML放在各自的文件夹中,分别命名为:方向纵向和方向横向。没有效果。视图永远不会显示

我也试过同样的方法来测试Scale-125和Scale-150预选赛,机制正在运行


有什么建议/提示吗

我同时解决了这个问题:

ResourceContext.SetGlobalQualifierValue(…)只能重写现有限定符。因此,如果你这样做:

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

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

我同时解决了这个问题:

ResourceContext.SetGlobalQualifierValue(…)只能重写现有限定符。因此,如果你这样做:

ResourceContext.SetGlobalQualifierValue("Custom", "Orientation-Landscape", ResourceQualifierPersistence.LocalMachine);
并将文件名设置为:MainPage.Custom-Orientation-Ladscape,一切都将按预期工作