我一直在尝试创建一组自定义文件名限定符,以便能够根据屏幕方向加载不同的视图(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限定符进行了相同的尝试,并且该机制正在起作用。
有什么建议/提示吗?