Windows Phone 8 更改重音和主题颜色 [英] Windows Phone 8 Change Accent and Theme Colour

查看:23
本文介绍了Windows Phone 8 更改重音和主题颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Windows Phone 8 创建一个应用程序,我想更改主题颜色,而不管用户在手机操作系统中设置的主题如何,与其他应用程序(例如 Skype)执行此操作的方式相同.

I am creating an Application for Windows Phone 8, and I would like to change the theme colour irrespective of the theme set by the user in the phone OS, in the same way that other applications do this (for example Skype).

到目前为止,我只能通过访问 XAML 中的 LayoutRoot 元素来更改背景颜色:

So far I have only managed to change the background colour, by accessing the LayoutRoot element in XAML:

this.LayoutRoot.Background = new SolidColorBrush(Colors.White);

和前景色:

(App.Current.Resources["PhoneForegroundBrush"] as SolidColorBrush).Color = Colors.Green;

但是,以下内容不适用于 Windows Phone 8:

However the following does not work on Windows Phone 8:

(App.Current.Resources["PhoneBackgroundBrush"] as SolidColorBrush).Color = Colors.White;
(App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush).Color = Colors.Yellow;

我不知道为什么我不能更改 PhoneBackgroundBrushPhoneAccentBrush 并且我尝试过谷歌搜索解决方案,但它们只适用于 windows phone 7 SDK.教程 此处适用于 WP 7但不是 WP 8.

I do not know why I cannot change the PhoneBackgroundBrush or the PhoneAccentBrush and I have tried googling solutions however they only work with the windows phone 7 SDK.The Tutorial here works on WP 7 but not WP 8.

谢谢!

推荐答案

Fabrice 绝对是在正确的轨道上.获取默认的 PhoneAccentBrush 并更改其颜色是可行的方法.

Fabrice is definitely on the right track. Getting the default PhoneAccentBrush and changing it's color is the way to go.

将此代码添加到您的应用程序构造函数的末尾,它将为您的应用程序覆盖 WP8 的强调色:

Add this code to the end of your App's constructor and it would override WP8's Accent colour for your app:

    Resources.Remove("PhoneAccentColor");
    Resources.Add("PhoneAccentColor", Colors.Magenta);
    ((SolidColorBrush)Resources["PhoneAccentBrush"]).Color = Colors.Magenta;

当我们运行此代码并单击

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