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

我一直在尝试创建一组自定义文件名限定符,以便能够根据屏幕方向加载不同的视图(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",ResourceQualifierPersistence.LocalMachine);
                    break;
            }

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

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

我已经对Scale-125和Scale-150限定符进行了相同的尝试,并且该机制正在起作用。

有什么建议/提示吗?

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

我同时解决了这个问题:

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

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

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

本文链接:https://www.f2er.com/3021586.html

大家都在问