wpf-notifyicon icon indicating copy to clipboard operation
wpf-notifyicon copied to clipboard

TrayIcon content does not react to DynamicResource changes

Open NikasZalias opened this issue 5 years ago • 13 comments

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?

NikasZalias avatar Jan 10 '20 07:01 NikasZalias

@punker76

NikasZalias avatar Jan 10 '20 09:01 NikasZalias

I'm interested in finding out what causes this behavior too. @NikasZalias were you able to fix this after all?

angelwzr avatar May 29 '20 15:05 angelwzr

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.

sirdoombox avatar Aug 09 '20 08:08 sirdoombox

Same

Symbai avatar Sep 22 '20 17:09 Symbai

Same here, I'm setting the MenuItem's header to a dynamicResource, it just does not change when the dynamicResource changes.

CoelWu avatar Apr 13 '21 14:04 CoelWu

@punker76

CoelWu avatar Apr 13 '21 14:04 CoelWu

Maybe someone can make a minimalistic example project for this?

Lakritzator avatar Apr 14 '21 18:04 Lakritzator

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.

Erapchu avatar Dec 03 '21 06:12 Erapchu

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.

Erapchu avatar Dec 03 '21 07:12 Erapchu

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!

DarkPro1337 avatar Jul 05 '22 10:07 DarkPro1337

Oh, as an example:

https://github.com/Erapchu/PasswordManager/blob/master/PasswordManager/Views/TrayIcon.xaml.cs

Erapchu avatar Jul 05 '22 10:07 Erapchu

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

Lakritzator avatar Sep 05 '22 07:09 Lakritzator

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();
}

Erapchu avatar Sep 05 '22 08:09 Erapchu