手机的Windows 8如何始终思考着一个问题,即使手机的主题变化 [英] Windows phone 8 How to be always on one theme even if phone's theme changed

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

问题描述

我的应用程序一般设计为主题,我使用 StaticResources 因此,如果用户改变他手机的主题为应用程序变得不可读,无法使用。

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.

例,迫使光主题:

Example to force the Light theme:

在代码的,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 应用模式:

当然,在设计准则使用的主题资源来确保您的应用程序适用于任何主题色和强调色推荐。

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.

不过,如果你真的想迫使黑暗的主题,这里是由鲁迪Huyn在他的博客提供了一个解决方案:的 http://www.rudyhuyn.com/blog/2013/01/18/forcer-un-theme -sous窗口电话-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构造函数中,检查灯光主题是否启用,如果是,你重写主题:

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 8如何始终思考着一个问题,即使手机的主题变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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