简体   繁体   English

如何在Windows Phone中更改应用程序栏的颜色?

[英]How to change color of the Application Bar in Windows Phone?

In my app, I want to have the color of the application bar be white and full opaque, with no regards to the theme. 在我的应用程序中,我希望应用程序栏的颜色为白色且完全不透明,而不考虑主题。 So far I have experimented with this. 到目前为止,我已经尝试过这个。

ApplicationBar.Opacity = 1;
ApplicationBar.BackgroundColor = Color.FromArgb(52, 50, 2, 181);

The result was a light pink color with some transparency. 结果是浅粉红色,有一些透明度。 Also, I would like to keep the same theme colored (light theme) icon buttons even if the theme is dark. 此外,即使主题很暗,我也希望保持相同的主题彩色(浅色主题)图标按钮。 I have seen apps in the WP Store (mainly Skype) that do that. 我见过WP Store(主要是Skype)中的应用程序。 Answers gladly appreciated. 答案很高兴欣赏。

Two ways, either in the XAML: 两种方式,在XAML中:

<phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar BackgroundColor="White" ForegroundColor="Black">
        <shell:ApplicationBar.Buttons>
            <shell:ApplicationBarIconButton Text="A button" IconUri="/Assets/AppBar/new.png" />
        </shell:ApplicationBar.Buttons>
    </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>

Or in the code behind: 或者在后面的代码中:

using System.Windows.Media;
...
ApplicationBar.ForegroundColor = Colors.Black; // Icon and text color
ApplicationBar.BackgroundColor = Colors.White; // Application bar background color

Essentially the BackgroundColor sets the background color of the application bar and ForegroundColor sets the icon and text color. 基本上, BackgroundColor设置应用程序栏的背景颜色, ForegroundColor设置图标和文本颜色。 Setting those will keep the value regardless of theme settings. 无论主题设置如何,设置它们都将保留该值。

You don't need to set the opacity , as the default value is 1 (full opaque). 您不需要设置opacity ,因为默认值为1(完全不透明)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM