问题描述
我认为这是一个非常普遍的问题,但我找不到适合我的解决方案.众所周知,WP支持深色和浅色主题.用户可以更改主题,并且有多种方法可以覆盖他的决定并以您选择的颜色主题显示所有内容.但是,我只是想对这两种主题类型做出反应,我想以正确的颜色显示图标.
I think this is a very common problem, but I cannot find a suitable solution for me. As you all know, WP supports a dark and a light theme. The user can change the theme and there are ways to override his decision and to display everything in the color theme you've selected. However, I'm just trying to react to this two theme types and I want to display icons in the correct color.
如果您使用应用程序栏,您可以从许多内置图标中进行选择,这些图标会自动从亮到暗,反之亦然.
If you use the Application Bar, you can select from many built in icons, which will be automatically inverted from light to dark and vice versa.
为什么不支持普通图像?例如:我想显示一个电话图标.我从内置图标中选择了一个并将其从 Microsoft SDK 文件夹复制到我的项目的 Image 文件夹中.如果用户使用深色主题,一切都会好起来的,因为在黑色背景上可以看到白色的电话图标.但是如果他切换到浅色主题,图标将不可见,因为它是白底白字.
Why isn't there any support for normal images? For example: I want to display a telephone icon. I've picked one from the built in icons and copied it from the Microsoft SDK folder to the Image folder of my project. If the user uses the dark theme, everything will be fine because the white telephone icon will be visible on the black background. But if he switches to the light theme, the icon will be invisible because it is white on white.
我完全了解文本框或背景颜色的样式资源,它们使用手机的强调色或主题色.但是为什么不支持我作为图像添加到 XAML 页面的简单图标?
I'm fully aware of the style resources for textboxes or background colors, which use the phone's accent or theme color. But why is it, that there is no support for simple icons which I added as Image to my XAML page?
当然,我可以在页面的构造函数中检测到用户处于暗模式还是亮模式.然后我会加载电话图标的黑色或白色版本.但是每次我访问该页面时都会进行此检查并减慢一切.每次添加主题感知图像时手动添加主题检查也很烦人.
Of course I could detect in the constructor of the page if the user is in dark or light mode. I would then load either a black or white version of the telephone icon. But this check will be done everytime I visit the page and slows everything down. It's also annoying to manually add the check for the theme each time I'm adding a theme aware image.
是否有任何仅适用于 XAML 的解决方案?或者至少易于维护?为什么我不能从一开始就使用 SDK 中的内置图像?它们已经提供深色和浅色版本,并且已经在应用程序栏中使用.
Is there any solution, which will work with XAML only? Or is at least easy to maintain? And why can't I use the built in images from the SDK right from the beginning? They are already available in dark and light versions and are already used in the application bar.
推荐答案
如果你想让图标像在操作栏中一样发挥作用,只需白色(如果是深色主题)和黑色(如果是浅色主题)然后你可以添加图像作为矩形的不透明蒙版,如下所示:
If you want the icon to function like in the actionbar, just be white (if dark theme) and black (if light theme) then you can add the image as an opacity mask to a rectangle, like this:
<Rectangle Fill="{StaticResource PhoneForegroundBrush}" Width="48" Height="48" >
<Rectangle.OpacityMask>
<ImageBrush ImageSource="/Images/my.icon.png" />
</Rectangle.OpacityMask>
</Rectangle>
其中 my.icon.png 是白色图像,就像您可以为操作栏选择的图像一样.
Where my.icon.png is a white image, like those you can choose for the actionbar.
这篇关于Windows Phone 8 中的自动暗/亮图标支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!