Windows phone 8 如何即使手机主题更改也始终保持一个主题 [英] Windows phone 8 How to be always on one theme even if phone's theme changed

查看:12
本文介绍了Windows phone 8 如何即使手机主题更改也始终保持一个主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序通常是为 dark 主题设计的,而我使用的是 StaticResources 所以如果用户将他手机的主题更改为 light应用变得无法读取和无法使用.

My app is generally designed for dark theme, and I'm using StaticResources So if the user changes his phone's theme to light the app gets unreadable and unusable.

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

I tried to change manually color of each element and avoid using StaticResources and things like:

Style="{StaticResource PhoneTextLargeStyle}"

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

and StaticResources for font and color. But this is a hard work.

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

How can I globally change the theme to my app think the phone theme is dark? (it's a windows phone 8 app)

推荐答案

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

Update : Since the release of Windows Phone 8.1, you can set the RequestedTheme attribute on any control, or even at the app level to override the Theme set by the users in the Settings.

强制使用 Light 主题的示例:

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

In code, within the constructor of the App class :

/// <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 应用程序模型:

For the old Windows Phone 8 application model :

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

It is of course recommended in the design guidelines to use the theme resources to make sure your app works with any theme and accent color.

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

However if you really want to force the dark theme, here is a solution provided by Rudy Huyn on his blog: http://www.rudyhuyn.com/blog/2013/01/18/forcer-un-theme-sous-windows-phone-8/

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

The idea is to add a method in your App class that will override all the system brushes with the colors of the dark theme:

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 主题,如果是,则覆盖主题:

Then, in the App constructor, you check whether the Light theme is enabled, and if it is, you override the theme:

if ((Visibility) Resources["PhoneLightThemeVisibility"] == Visibility.Visible)
{
    DarkTheme();
}

这篇关于Windows phone 8 如何即使手机主题更改也始终保持一个主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆