Recently when I was working on one of my personal project in WPF. I added the ability to change themes for this WPF applications, but the difficulty that I faced was to change the Taskbar icon with respect to the theme.
Normally we add a static icon for any application. But sometimes that icon doesn’t reflect the theme accent. In order to solve this, I did some research (googled) and figured out a way to update the application taskbar icon.
I wrote a simple IconMaker class, which converts WPF Canvas into an image.
Now using this class, we can change the taskbar icon, when we change the theme. It’s enough to change the icon of the applications main window.
Application.Current.MainWindow.Icon = IconMaker.Icon(value);
Below image show, how this class works, when we change the theme. Look at the Taskbar Icon for the current application.
The minimum requirement for this technique to work is that we need to provide XAML Geometry object as an input. I use icons from ModernUIIcons or updated Material Design Icons, from where I extract the Path data and create a WPF Canvas to render PNG image into memory.
Some background about the application
I developed this application to learn the different concepts of WPF. It uses Caliburn.Micro for MVVM and the UI gets it look from combination of multiple opensource projects, one being Modern UI for WPF (some of the controls are not useful for me and are not MVVM freindly, so I did removed those from my library) and few controls like sidebar popup from MahApps.Metro and finally Entity Frameowork for ORM.
BTW, the current project is a private repository at BitBucket. I will update this post, if I make this public in future.
Please let me know, your suggestions and feedback in the below comments section and if anyone has come forth with such need.