I get the exception: System.Windows.Markup.XamlParseException: 'Cannot access Freezable 'System.Windows.Media.Effects.DropShadowEffect' across threads because it cannot be frozen.'
when opening a context menu.
I am using several MetroWindows dialogs, each has his own dialog thread, instanciated as thread.SetApartmentState(ApartmentState.STA).
Exception occurres when in one dialog a menu or context menu is openend and afterwards in a different dialog a context menu is trying to be opened.
This exception did not occur with MahApps version V1.6.4.
Turning off drop shadow with "HasDropShadow=False" on context menu did not improve the situation.
MahApps.Metro version: v2.0.0
Windows build number: Win10 1909 [Version 10.0.18363.836]
Visual Studio: 2019 16.6.0
Target Framework: .Net Core 3.1 (v4.5.2, v4.7.2)
HI @gordon771
would it be possible for you to share a sample App showing the issue? Would be best if you could create a repro on github for it.
Thank you and happy coding
Tim
Hi @timunie
many thanks for your effort.
I setup a repository for you with sample code. There are 3 branches: main branch with described bug (open app -> open window 1 from pulldown menu -> open context menu via button within window 1 -> open context menu within main menu -> execption); 'native' branch shows that it is working without MahApps.Metro and finally my workaround in branch 'working', where I decentralized MahApps declarations into MainWindow and WindowBase.
During my investigations I saw that the DropShadowEffect is not freezed, like the SolidColorBrushes within menu and contextmenu styles.
Best regards,
Gordon
Hi @gordon771
thank you for the sample. You are right, it seems to be related to MahApps. if I replace it with a normal Window it works.
Would it be possible to make this repro public so that @punker76 can check it out also? I think there is no private code in it.
happy coding
Tim
Hi @timunie and @punker76,
I made the sample repro public.
Thanks again for your effort!
Best regards,
Gordon
and here is the link: https://github.com/gordon771/MahAppsTest
@gordon771 I created a PR at your test project https://github.com/gordon771/MahAppsTest/pull/2
If you want to use WPF windows in different threads then it's necessary to add the MahApps resources to each window.
Hi @punker76 ,
okay, that was my workaround so far.
Thank you for your answer and your effort!
Best regards,
Gordon
Most helpful comment
Hi @timunie and @punker76,
I made the sample repro public.
Thanks again for your effort!
Best regards,
Gordon