Windows phone 8即使手机的主题发生变化,如何始终在一个主题上

use*_*629 8 c# xaml windows-phone-7 windows-phone-8

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

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

Style="{StaticResource PhoneTextLargeStyle}"
Run Code Online (Sandbox Code Playgroud)

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

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

Ren*_*ont 20

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

强制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;
    }
}
Run Code Online (Sandbox Code Playgroud)

或者在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>
Run Code Online (Sandbox Code Playgroud)

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

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

但是,如果你真的想强迫黑暗的主题,这里是Rudy Huyn在他的博客上提供的解决方案:http://www.rudyhuyn.com/blog/2013/01/18/forcer-un-theme-sous-windows -phone-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);
}
Run Code Online (Sandbox Code Playgroud)

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

if ((Visibility) Resources["PhoneLightThemeVisibility"] == Visibility.Visible)
{
    DarkTheme();
}
Run Code Online (Sandbox Code Playgroud)


小智 12

我只是想推荐Jeff Wilcox的"Windows Phone Theme Manager"nuget软件包作为一种简单的方法来实现这个功能,适用于明暗主题.

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

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

ThemeManager.ToDarkTheme();
Run Code Online (Sandbox Code Playgroud)

要么

ThemeManager.ToLightTheme();
Run Code Online (Sandbox Code Playgroud)