如何使应用程序栏中的图标根据当前主题而变化?

发布于 2024-10-27 17:02:32 字数 91 浏览 2 评论 0原文

在 WP7 应用程序中,使应用程序栏中的图标与当前主题(浅色/深色)相匹配的首选方法是什么?我真的需要使用“hack”来检测当前主题,并据此设置图标,还是有更好的方法?

In WP7 apps, what is the preferred way to make the icons in the Application Bar match the current theme (light/dark)? Do I really need to use the "hack" to detect the current theme, and set the icons based on that, or is there a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

安静被遗忘 2024-11-03 17:02:32

如果您使用默认(白色)图像,或创建类似的透明白色 PNG 图像,则无需执行任何操作;操作系统会为您处理它。

If you use the default (white) images, or create similar PNG images that are white on transparent, then you don't need to do anything; the operating system handles it for you.

夜深人未静 2024-11-03 17:02:32

只需使用 PhoneDarkThemeVisibility 资源:

<Image Source="pathToLightImage.png" Visibility="{StaticResource PhoneLightThemeVisibility}" />

<Image Source="pathToDarkImage.png" Visibility="{StaticResource PhoneDarkThemeVisibility}" />

根据用户设置,仅显示两个项目之一。它有芒果版本。

另一种选择是仅使用一个配置了 OpacityMask 的图像。您可以在此处了解更多信息。

Just use PhoneDarkThemeVisibility resource:

<Image Source="pathToLightImage.png" Visibility="{StaticResource PhoneLightThemeVisibility}" />

<Image Source="pathToDarkImage.png" Visibility="{StaticResource PhoneDarkThemeVisibility}" />

Depending on user settings only one of two items will be displayed. It is available in Mango.

Another option is to use only one image with OpacityMask configured. You can find out more about it here.

丶情人眼里出诗心の 2024-11-03 17:02:32

我建议您存储两组图标(深色和浅色),并在后面的代码中动态创建应用程序栏。然后让用户可以选择他们想要的主题,并使用简单的 if...else 语句处理加载的图标。

现在,为了确定用户正在使用哪个主题,您可以检查“phonelightthemevisibility”资源。检查该资源是否可见。

Visibility v = (Visibility)Resources["PhoneLightThemeVisibility"];
if(v = System.Windows.Visibility.Visible)
{
   //Use icons for light theme
}
else
{
   //Use icons for dark theme
}

让我知道这是否有帮助。

I would suggest you store both sets of icons, dark and light, and create the app bar dynamically in the code behind. Then give the user the option to choose which theme they would like and handle the icons that get loaded using a simple if...else statement.

Now in order to determine which theme the user is using you can check the "phonelightthemevisibility" resource. Check if that resource is visible.

Visibility v = (Visibility)Resources["PhoneLightThemeVisibility"];
if(v = System.Windows.Visibility.Visible)
{
   //Use icons for light theme
}
else
{
   //Use icons for dark theme
}

Let me know if this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文