Creating image control inverts its colors depending on the theme

I’m trying to figure out how to have an Image control in a Windows Phone application, invert its colors based on the global background setting (either Dark or Light), selected by the user in Settings-> Themes-> Background.

+5
source share
3 answers

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

Instead, due to the overhead of doing this on the phone, you have to create both versions of the image during development / assembly, and then choose which version to display from your code, having detected the Visibility and opacity of the theme .

+5
source

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

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

The code is as follows:

 <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" /> 
+4
source

This question is now 1.5 years old. But here is the easiest way to do what you want. The above example 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> 
+4
source

Source: https://habr.com/ru/post/895928/


All Articles