使图像控件根据主题反转其颜色

发布于 2024-10-11 03:09:03 字数 111 浏览 4 评论 0原文

我正在尝试弄清楚如何让 Windows Phone 应用程序中的 Image 控件根据用户在“设置”中选择的全局背景设置(“深色”或“浅色”)反转其颜色->主题->背景。

I'm trying to work out how to have an Image control in my Windows Phone application invert its colors based on the global background setting (either "Dark" or "Light") chosen by the user in Settings->Themes->Background.

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

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

发布评论

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

评论(3

囚你心 2024-10-18 03:09:03

框架内没有内置的方法来反转图像颜色。

相反,由于在手机上执行此操作的开销,您应该在设计/构建时创建图像的两个版本,然后通过检测 主题可见性和不透明度

There is no built-in way to invert image colors within the framework.

Instead, because of the overhead of doing this on the phone, you should create both versions of the image at design/build time and then choose which version to display from your code by detecting Theme Visibility and Opacity.

雨轻弹 2024-10-18 03:09:03

我必须补充一点,我最终所做的是马特所写内容的延续。

  • 创建两个具有不同版本图像(深色和浅色)的不同图像,并将它们放置在完全相同的位置,
  • 根据主题资源设置它们的可见性,

代码如下所示:

<Image Height="30" HorizontalAlignment="Center" Margin="0,0,0,220" Name="imgDark" Stretch="Fill" Visibility="{StaticResource PhoneLightThemeVisibility}" VerticalAlignment="Center" Width="30" Source="/MyApplication;component/imageDarkTheme.png" />
<Image Height="30" HorizontalAlignment="Center" Margin="0,0,0,220" Name="imgLoading" Stretch="Fill" Visibility="{StaticResource PhoneDarkThemeVisibility}" VerticalAlignment="Center" Width="30" Source="/MyApplication;component/imageLightTheme.png" />

I must add that what i did in the end was a continuation of what Matt wrote.

  • create two different images that have different versions of the image (dark and light) and place them in the exact same position
  • set their visibility based on the theme resource

the code looks like this:

<Image Height="30" HorizontalAlignment="Center" Margin="0,0,0,220" Name="imgDark" Stretch="Fill" Visibility="{StaticResource PhoneLightThemeVisibility}" VerticalAlignment="Center" Width="30" Source="/MyApplication;component/imageDarkTheme.png" />
<Image Height="30" HorizontalAlignment="Center" Margin="0,0,0,220" Name="imgLoading" Stretch="Fill" Visibility="{StaticResource PhoneDarkThemeVisibility}" VerticalAlignment="Center" Width="30" Source="/MyApplication;component/imageLightTheme.png" />
白云不回头 2024-10-18 03:09:03

这个问题已经有1.5年历史了。但是这里是做你想做的事情的最简单的方法。那里给出的例子非常简单,比如

<Button>
    <Image Stretch="None" Source="{Binding Converter={StaticResource ThemedImageConverter}, ConverterParameter={StaticResource PhoneBackgroundColor} }"
           DataContext="/WP7SampleProject4;component/Images/{0}/appbar.feature.camera.rest.png" />
</Button>

This Question is 1.5 years old now. But here is the easiest way to do what you want. The example given there is very simple like

<Button>
    <Image Stretch="None" Source="{Binding Converter={StaticResource ThemedImageConverter}, ConverterParameter={StaticResource PhoneBackgroundColor} }"
           DataContext="/WP7SampleProject4;component/Images/{0}/appbar.feature.camera.rest.png" />
</Button>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文