5

我如何知道在设置中选择了什么主题(浅色或深色)?我想使用条件语句,例如

if (darkTheme) {..}
else {..}
4

5 回答 5

6

您想在 Windows Phone 上的主题的官方 MSDN 页面中找到您的响应。

在“确定主题背景”部分中表明:

// Determine the visibility of the dark background.
Visibility darkBackgroundVisibility = 
    (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"];

// Write the theme background value.
if (darkBackgroundVisibility == Visibility.Visible)
{
    textBlock1.Text = "background = dark";
}
else
{
    textBlock1.Text = "background = light";
}

此外,在此页面中,您还参与了“主题强调色”。恢复用户定义的两种主要颜色(背景色和强调色)。

于 2013-08-13T14:05:34.727 回答
3
if( (Visibility)App.Current.Resources["PhoneDarkThemeVisibility"] )
...
else
...
于 2013-08-13T12:04:04.093 回答
1

我发现确定主题的最简单方法是使用:

public bool darkTheme = ((Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"] == Visibility.Visible);

是 darkTheme 为 true 则所选主题为暗色,而 false 为亮色。

然后在任何程序中只使用一个简单的if语句,例如:

if (darkTheme == true)
{
    //Do some stuff related to dark theme
}

else 
{
    //Do some stuff related to light theme
} 
于 2013-08-13T16:51:20.003 回答
0
 // Detecting the current theme. 

    private static Color lightThemeBackground = Color.FromArgb(255, 255, 255, 255); 
private static Color darkThemeBackground = Color.FromArgb(255, 0, 0, 0); 
rivate static SolidColorBrush backgroundBrush; 

internal static AppTheme CurrentTheme 
    {
        get
        {
           if ( backgroundBrush == null )
               backgroundBrush = Application.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush;

           if (backgroundBrush.Color == lightThemeBackground)
                return AppTheme.Light;
           else if (backgroundBrush.Color == darkThemeBackground)
                return AppTheme.Dark;

           return AppTheme.Dark;
        } 
    }
于 2013-08-13T12:06:47.243 回答
0

奖励:安装 Jeff Wilcox 的 ThemeManager,只需一行代码即可在您的应用程序中切换明暗主题!

http://www.jeff.wilcox.name/2012/01/phonethememanager/

于 2013-08-13T12:28:22.990 回答