如何按下时更改应用程序栏按钮的颜色 [英] How to Change the Color of Application Bar Buttons when Pressed

查看:225
本文介绍了如何按下时更改应用程序栏按钮的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是有趣的问题,我想知道是否有可能在主题的Windows Phone 8应用程序栏按钮按下时使用比当前口音的颜色作为按钮的背景之外另一种颜色。我目前在代码中创建我的应用程序栏在我的测试应用程序背后。是否有一个如何做到这一点有什么建议?我还没有找到一个资源联机的任何地方。基本上我有什么,现在是用于测试目的一个非常简单的应用程序吧。



MainPage.xaml.cs中



 私人无效BuildLocalizedApplicationBar()
{
//设置页面的应用程序任务栏到应用程序任务栏的新实例。
=应用程序任务新应用程序任务栏();

//创建一个新的按钮和文本值设置为从AppResources的本地化字符串。
ApplicationBarIconButton newButton =新ApplicationBarIconButton(新的URI(/资产/ AppBar / new.png,UriKind.Relative));
newButton.Text =新;
newButton.Click + = newButton_Click;
ApplicationBar.Buttons.Add(newButton);
}


解决方案

如果您设置的应用程序任务栏的前景为类似#FFFEFEFE白色和#FF010101用于黑色的ApplicationBarIconButtons不会使用AccentBrush按下它们时,它们将使用应用程序任务栏的定义前景颜色!



我花了时间,找到解决这一问题,但它有一定的道理:微软使用白色(#FFFFFFFF)和黑色(#00000000)为他们的黑暗与光明的主题。在这种情况下,应用程序任务栏使用AccentBrush,如果前景设置为不同的颜色,它使用的定义之一。



所以,你只需要添加以下行(白):

  ApplicationBar.Foreground =新的SolidColorBrush(Color.FromArgb(255,254,254,254)); 


An interesting question, I was wondering if it is possible to theme the application bar buttons in Windows Phone 8 to use another color other than the current accent color as the background of the button when pressed. I am currently creating my app bar in code behind in my test application. Are there any suggestions of how to do this? I have not yet found a resource online anywhere. Essentially what I have right now is a very simple app bar for testing purposes.

MainPage.xaml.cs

private void BuildLocalizedApplicationBar()
{
    // Set the page's ApplicationBar to a new instance of ApplicationBar.
    ApplicationBar = new ApplicationBar();

    // Create a new button and set the text value to the localized string from AppResources.
    ApplicationBarIconButton newButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/new.png", UriKind.Relative));
    newButton.Text = "new";
    newButton.Click += newButton_Click;
    ApplicationBar.Buttons.Add(newButton);
}

解决方案

If you set the ApplicationBar's Foreground to something like #FFFEFEFE for white and #FF010101 for black the ApplicationBarIconButtons will not use the AccentBrush when they are pressed, they will use the defined Foreground Color of the ApplicationBar!

It took me hours to find the solution to that problem but it makes some sense: Microsoft uses White(#FFFFFFFF) and Black (#00000000) for their dark and light theme. In this case the ApplicationBar uses the AccentBrush and if the Foreground is set to a different color it uses the defined one.

So you just need to add the following line (white):

ApplicationBar.Foreground = new SolidColorBrush(Color.FromArgb(255, 254, 254, 254));

这篇关于如何按下时更改应用程序栏按钮的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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