问题
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);
}
回答1:
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));
来源:https://stackoverflow.com/questions/18479826/how-to-change-the-color-of-application-bar-buttons-when-pressed