如何在按下时更改应用程序栏按钮的颜色

Mat*_*hew 3 c# application-bar windows-phone-8

一个有趣的问题,我想知道是否有可能将Windows Phone 8中的应用程序栏按钮设置为使用除当前强调颜色之外的其他颜色作为按下时按钮的背景.我目前正在我的测试应用程序中创建我的应用程序栏.有什么建议怎么做?我还没有在任何地方在线找到资源.基本上我现在拥有的是一个非常简单的应用栏,用于测试目的.

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);
}
Run Code Online (Sandbox Code Playgroud)

Mal*_*etz 9

如果将ApplicationBar的Foreground设置为白色的#FFFEFEFE和黑色的#FF010101,则ApplicationBarIconButtons在按下时不会使用AccentBrush,它们将使用ApplicationBar定义的前景颜色!

我花了几个小时才找到解决这个问题的方法,但它有一定道理:微软使用白色(#FFFFFFFF)和黑色(#00000000)作为他们的黑暗和浅色主题.在这种情况下,ApplicationBar使用AccentBrush,如果Foreground设置为不同的颜色,则使用已定义的颜色.

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

ApplicationBar.Foreground = new SolidColorBrush(Color.FromArgb(255, 254, 254, 254));
Run Code Online (Sandbox Code Playgroud)