【发布时间】:2017-04-18 21:06:43
【问题描述】:
我更新到 Xamarin.Forms 和 Xamarin.Forms.Pages V2.3.5.233-pre1 并且我的动态主题更改在当前屏幕上停止工作。以前,当我更改它和任何打开的屏幕时,它会更改我所在的屏幕。现在似乎需要我关闭任何打开的屏幕并重新打开它。我不确定如何刷新屏幕,因为这确实不是一个理想的选择。
这是我更改主题的方法。任何意见将是有益的。如果我回到以前的版本,它可以正常工作,但是我失去了我需要的新功能。
我只是使用给定的深色和浅色主题 我有一个简单的选择器来选择它们。
<StackLayout Orientation="Horizontal" >
<Label Text="Theme" HorizontalOptions="Start" VerticalOptions="Center" />
<Picker SelectedIndex="{Binding Theme,Mode=TwoWay}" HorizontalOptions="EndAndExpand" VerticalOptions="Center">
<Picker.Items>
<x:String>Light</x:String>
<x:String>Dark</x:String>
</Picker.Items>
</Picker>
</StackLayout>
我通过将选择器绑定到下面的主题来更改它:
public int Theme
{
get { return _theme; }
set
{
_theme = value;
App.SetTheme = (MySettings.Theme)value;
}
}
在应用程序中:
public static MySettings.Theme SetTheme {
set
{
if (value == MySettings.Theme.Light)
{
App.Current.Resources = new ResourceDictionaryLight();
}
else if (value == MySettings.Theme.Dark)
{
App.Current.Resources = new ResourceDictionaryDark();
}
}
}
ResourceDictionaryLight xaml 像这样:
<?xml version="1.0" encoding="utf-8"?>
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ChurchApp.ResourceDictionaryLight"
MergedWith="light:LightThemeResources"
xmlns:light="clr-namespace:Xamarin.Forms.Themes;assembly=Xamarin.Forms.Theme.Light">
</ResourceDictionary>
感觉像一个错误(无论是旧的还是新的),因为它改变了它的工作方式,而我没有更改任何代码。
【问题讨论】:
标签: xaml xamarin xamarin.forms themes resourcedictionary