使用c#在Windows手机(浅色或深色)中的主题

时间:2013-08-13 12:01:24

标签: c# silverlight windows-phone-7 colors

我如何知道在设置中选择的主题(亮或暗)? 我想使用条件语句,如

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

5 个答案:

答案 0 :(得分:6)

您想在official MSDN page for Windows Phone上的主题中找到您的回复。

在“确定主题背景”部分中指出:

// 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";
}

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

答案 1 :(得分:3)

if( (Visibility)App.Current.Resources["PhoneDarkThemeVisibility"] )
...
else
...

答案 2 :(得分:1)

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

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

是darkTheme是真的然后所选主题是黑暗的,而假的是光。

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

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

else 
{
    //Do some stuff related to light theme
} 

答案 3 :(得分: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;
        } 
    }

答案 4 :(得分:0)

奖励:安装Jeff Wilcox的ThemeManager,只需一行代码即可在应用中切换浅色和深色主题!

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