8

我的应用程序通常是为dark主题设计的,并且我正在使用StaticResources因此,如果用户将手机的主题更改为应用程序,light则该应用程序将变得不可读且无法使用。

我试图手动更改每个元素的颜色并避免使用类似的StaticResources东西:

Style="{StaticResource PhoneTextLargeStyle}"

以及StaticResources字体和颜色。但这是一项艰苦的工作。

如何将主题全局更改为我的应用程序认为手机主题是黑暗的?(这是一个 Windows Phone 8 应用程序)

4

2 回答 2

20

更新:自Windows Phone 8.1发布以来,您可以在任何控件上设置RequestedTheme属性,甚至可以在应用程序级别覆盖用户在 Settings 中设置的 Theme

强制使用 Light 主题的示例:

在代码中,在 App 类的构造函数中:

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public sealed partial class App : Application
{
    private TransitionCollection transitions;

    /// <summary>
    /// Initializes the singleton application object.  This is the first line of authored code
    /// executed, and as such is the logical equivalent of main() or WinMain().
    /// </summary>
    public App()
    {
        this.RequestedTheme = ApplicationTheme.Light;

        this.InitializeComponent();
        this.Suspending += this.OnSuspending;
    }
}

在 XAML 中

<Application
    x:Class="App26.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    RequestedTheme="Light"
    xmlns:local="using:App26">
</Application>

对于旧的Windows Phone 8应用程序模型:

当然,在设计指南中建议使用主题资源来确保您的应用程序适用于任何主题和强调色。

但是,如果您真的想强制使用黑暗主题,这里是 Rudy Huyn 在他的博客上提供的解决方案:http ://www.rudyhuyn.com/blog/2013/01/18/forcer-un-theme-sous-windows -电话8/

这个想法是在您的 App 类中添加一个方法,该方法将使用深色主题的颜色覆盖所有系统画笔:

private void DarkTheme()
{
    ((SolidColorBrush)Resources["PhoneRadioCheckBoxCheckBrush"]).Color = ((SolidColorBrush)Resources["PhoneRadioCheckBoxBorderBrush"]).Color = ((SolidColorBrush)Resources["PhoneForegroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneBackgroundBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
    ((SolidColorBrush)Resources["PhoneContrastForegroundBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
    ((SolidColorBrush)Resources["PhoneContrastBackgroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneDisabledBrush"]).Color = Color.FromArgb(0x66, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneProgressBarBackgroundBrush"]).Color = Color.FromArgb(0x19, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneTextCaretBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
    ((SolidColorBrush)Resources["PhoneTextBoxBrush"]).Color = Color.FromArgb(0xBF, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneTextBoxForegroundBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
    ((SolidColorBrush)Resources["PhoneTextBoxEditBackgroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneTextBoxReadOnlyBrush"]).Color = Color.FromArgb(0x77, 0x00, 0x00, 0x00);
    ((SolidColorBrush)Resources["PhoneSubtleBrush"]).Color = Color.FromArgb(0x99, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneTextBoxSelectionForegroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneButtonBasePressedForegroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneTextHighContrastBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneTextMidContrastBrush"]).Color = Color.FromArgb(0x99, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneTextLowContrastBrush"]).Color = Color.FromArgb(0x73, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneSemitransparentBrush"]).Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x00);
    ((SolidColorBrush)Resources["PhoneChromeBrush"]).Color = Color.FromArgb(0xFF, 0x1F, 0x1F, 0x1F);

    ((SolidColorBrush)Resources["PhoneInactiveBrush"]).Color = Color.FromArgb(0x33, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneInverseInactiveBrush"]).Color = Color.FromArgb(0xFF, 0xCC, 0xCC, 0xCC);
    ((SolidColorBrush)Resources["PhoneInverseBackgroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
    ((SolidColorBrush)Resources["PhoneBorderBrush"]).Color = Color.FromArgb(0xBF, 0xFF, 0xFF, 0xFF);
}

然后,在 App 构造函数中,检查是否启用了 Light 主题,如果是,则覆盖主题:

if ((Visibility) Resources["PhoneLightThemeVisibility"] == Visibility.Visible)
{
    DarkTheme();
}
于 2013-07-11T00:22:44.357 回答
12

我只是想推荐 Jeff Wilcox 的 'Windows Phone Theme Manager' nuget 包,作为为浅色和深色主题实现此功能的简单方法。

http://www.nuget.org/packages/PhoneThemeManager/

只需在 App 构造函数中添加一个函数调用:

ThemeManager.ToDarkTheme();

或者

ThemeManager.ToLightTheme();
于 2013-10-10T20:54:27.673 回答