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

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

问题描述

我正在为Windows Phone 8创建应用程序,并且我想更改主题颜色,而不考虑用户在手机操作系统中设置的主题,其方式与其他应用程序(例如Skype)相同。



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

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

前景颜色:

 (App.Current.Resources [PhoneForegroundBrush] as SolidColorBrush).Color = Colors.Green;但是以下操作在Windows Phone 8上不起作用:


$ b


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

我不知道为什么我不能改变 PhoneBackgroundBrush PhoneAccentBrush ,我已经尝试谷歌解决方案,但他们只能使用windows phone 7 SDK.The教程这里适用于WP 7,但不适用于WP 8。



谢谢!

解决方案

Fabrice绝对是在正确的轨道上。获取默认PhoneAccentBrush并更改它的颜色是要走的路。



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

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



当我们运行此代码并单击< Button /> / code>,您可以看到新的Accent颜色:




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).

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);

And the Foreground Colour:

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

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;

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.

Thank you!

解决方案

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

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;

When we run this code and click a <Button /> you can see the new Accent colour:

这篇关于Windows Phone 8更改重音和主题颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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