1 - 是否可以使用 2.3.x 版本中引入的 Xamarin.Forms 主题(下面的链接)在浅色和深色主题之间切换。有什么解决办法吗?https://developer.xamarin.com/guides/xamarin-forms/user-interface/themes/ https://developer.xamarin.com/guides/xamarin-forms/user-interface/themes/
2 - 我还看到此版本自推出以来一直处于预览状态。是否存在任何问题,我们无法在生产中使用它?
接受的答案不符合Microsoft 演示的约定 https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/themes/.
假设您已经安装了这些软件包,Xamarin.Forms.Themes.Base https://www.nuget.org/packages/Xamarin.Forms.Theme.Base/, Xamarin.Forms.Themes.Light https://www.nuget.org/packages/Xamarin.Forms.Theme.Light/1.0.0.43-pre1, and Xamarin.Forms.Themes.Dark https://www.nuget.org/packages/Xamarin.Forms.Theme.Dark/1.0.0.43-pre1, 和你的App.xaml好像,
<?xml version="1.0" encoding="utf-8" ?>
<Application
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:light="clr-namespace:Xamarin.Forms.Themes;assembly=Xamarin.Forms.Theme.Light"
xmlns:dark="clr-namespace:Xamarin.Forms.Themes;assembly=Xamarin.Forms.Theme.Dark"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyNamespace.MyApp">
<Application.Resources>
<ResourceDictionary MergedWith="light:LightThemeResources">
...
</ResourceDictionary>
</Application.Resources>
</Application>
您可以使用以下命令在运行时更改主题:
public enum Themes
{
Dark,
Light
}
var origin = App.Current.Resources;
switch (theme)
{
case Themes.Dark:
origin.MergedWith = typeof(DarkThemeResources);
break;
case Themes.Light:
origin.MergedWith = typeof(LightThemeResources);
break;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)