I use below code to set up button background image using a png file with white image.
ImageBrush brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri(@"/Images/delete.png", UriKind.Relative));
btnDel.Background = brush;
The png file has a white image. In the Dark Theme, I can see the white image from the png file. But when I change the Theme to Light, I can no longer see the white image.
Do I need to detect the theme being set by the user then use another png file with a black image?
I wrote up a blog post a while back that included a custom ResourceDictionary implementation that supports swapping between two ResourceDictionaries depending on the theme.
It works with the Visual Studio designer (Cider) and Blend but it doesn’t swap to light when using that preview mechanism in Blend. Unfortunately, due to how Blend processes resources, it looks like it’s going to remain that way for the foreseeable future.
You can read the original post for additional information, but I’ll include the code here:
You can then define light/dark specific resources like this (or you can put them in their own resource XAML file):
You can then reference them on your page like this: