【问题标题】:Windows Phone 7 Background Theme setting - App developmentWindows Phone 7 背景主题设置 - 应用程序开发
【发布时间】:2010-11-21 14:58:11
【问题描述】:

如何在我的代码中判断手机的“主题”是什么(即浅色或深色)?

更新:

好的,在做了更多研究之后,我找到了一些似乎可以满足我需要的东西。但是,也许有更好的方法?

想法?

以下是我发现现在可以回答我的问题的内容:

var backColor = Resources["PhoneBackgroundColor"];

【问题讨论】:

标签: windows-phone-7


【解决方案1】:

在早期的 beta 版本中,执行此操作的方法是检查 PhoneBackgroundColor 的 RGB 值,正如其他人在此处指出的那样。然而,这已经改变了。
现在这样做的首选方法是检查“PhoneLightThemeVisibility”的可见性(即使检查 RGB 值仍然有效):

Visibility v = (Visibility)Resources["PhoneLightThemeVisibility"];
if (v == System.Windows.Visibility.Visible)
{
    // Light theme
}
else
{
    // Dark theme
}

HTH

【讨论】:

    【解决方案2】:

    目前,检查PhoneBackgroundColor 的值似乎是检测主题的公认方法。您可以通过以下代码检查该值,该代码来自this post

    private Color lightThemeBackground = Color.FromArgb(255, 255, 255, 255);
    private Color darkThemeBackground = Color.FromArgb(255, 0, 0, 0);
    
    
    
    
    private void DisplayState()
    {
    
    SolidColorBrush backgroundBrush = Application.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush;
    
    if (backgroundBrush.Color == lightThemeBackground)
    {
    
    // you are in the light theme
    
    }
    else
    {
    
    // you are in the dark theme
    
    }
    
    }
    

    【讨论】:

    • 检查 RGB 值有效,但首选新的“PhoneLightThemeVisibility”资源 - 请参阅我的答案。
    猜你喜欢
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    • 2012-07-07
    相关资源
    最近更新 更多