wpf-notifyicon
wpf-notifyicon copied to clipboard
TrayIcon content does not react to DynamicResource changes
How can I make my TrayIcon react to Theme changes? When I change my app theme from light to dark or vice versa, tray icon stays the same until I restart app. Why is it like that?
@punker76
I'm interested in finding out what causes this behavior too. @NikasZalias were you able to fix this after all?
I'm also having similar issues using MahApps styles for the ContextMenu and MenuItem, for some reason only the foreground hover brush is changed when you change themes, but the foreground/background is not.
Same
Same here, I'm setting the MenuItem's header to a dynamicResource, it just does not change when the dynamicResource changes.
@punker76
Maybe someone can make a minimalistic example project for this?
As a solution: subscribe to TrayContextMenuOpen event of TaskbarIcon, and call UpdateDefaultStyle for context menu that required to be updated. Or call UpdateDefaultStyle when theme changed.
Popup control that host context menu or other controls can't correctly get dynamic resources changes from Application merged resource I guess. Popup on the same visual level where Application exists.
As a solution: subscribe to TrayContextMenuOpen event of TaskbarIcon, and call UpdateDefaultStyle for context menu that required to be updated. Or call UpdateDefaultStyle when theme changed.
Working as intended now, much thanks!
Oh, as an example:
https://github.com/Erapchu/PasswordManager/blob/master/PasswordManager/Views/TrayIcon.xaml.cs
I need to look into this again, I am also faced with the issue, so maybe I can add something to support a style update.
Btw. example link mentioned above moved to here: https://github.com/Erapchu/SinglePass.WPF/blob/master/SinglePass.WPF/Views/TrayIcon.xaml.cs
I renamed repo, thanks @Lakritzator Want to leave this solution here, if anyone need it
private void TaskbarIcon_TrayContextMenuOpen(object sender, RoutedEventArgs e)
{
// To apply DynamicResource changes
TrayIconContextMenu?.UpdateDefaultStyle();
}