C# 在Xamarin中,使用OnIdiom和OnIdiom
为什么MergedWith ResourceDictionary属性不支持Onidom功能? 此代码工作良好:C# 在Xamarin中,使用OnIdiom和OnIdiom,c#,xaml,xamarin,xamarin.forms,C#,Xaml,Xamarin,Xamarin.forms,为什么MergedWith ResourceDictionary属性不支持Onidom功能? 此代码工作良好: <ResourceDictionary.MergedWith>theme:PhoneTheme</ResourceDictionary.MergedWith> 主题:电话主题 此选项将MergedWith属性设置为null: <ResourceDictionary.MergedWith> <OnIdiom x:TypeArgumen
<ResourceDictionary.MergedWith>theme:PhoneTheme</ResourceDictionary.MergedWith>
主题:电话主题
此选项将MergedWith属性设置为null:
<ResourceDictionary.MergedWith>
<OnIdiom x:TypeArguments="x:String">
<OnIdiom.Phone>theme:PhoneTheme</OnIdiom.Phone>
<OnIdiom.Tablet>theme:TabletTheme</OnIdiom.Tablet>
</OnIdiom>
</ResourceDictionary.MergedWith>
主题:电话主题
主题:桌面主题
手机习惯用法和平板电脑习惯用法之间是否存在使用不同主题的解决方案?目前不支持,但已经提供
一种解决方法是为手机和平板电脑创建单独的页面,并依赖于习惯用法show-one-page或show-one-page。在这个页面上,你可以有自己的主题。我想这是你目前能做的最好的了。在这个阶段,你目前不能在XAML中做这件事,但是你可以用一个代码隐藏文件来解决它。我使用应用程序xaml和codebehind动态更改主题。然后,只需将手机和平板电脑主题的标准继承转换为常见的颜色、样式等。只需覆盖每个Iioom特定主题中需要的内容 MyApp.xaml
嗯,我已经这么做了,但我想简化习语主题化。谢谢你的回答!这是一个好主意,但合并后的资源字典被视为一个动态资源。这对我不太好。
<Application ...>
<ResourceDictionary x:Name="appTheme"> <!-- Name the Resource Dict //-->
...Any converters, etc
</ResourceDictionary>
</Application>
public partial class MyApp : Application
{
public MyApp()
{
InitializeComponent();
// Toggle appTheme.MergedWith based on Idiom
appTheme.MergedWith = Device.Idiom == TargetIdiom.Phone ? typeof(PhoneTheme) : typeof(TabletTheme);
}
}