Mahapps.metro: Freeze exception on DropShadowEffect when opening a contextmenu

Created on 12 Oct 2020  路  7Comments  路  Source: MahApps/MahApps.Metro

Describe the bug

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).

Steps to reproduce

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.

Actual behavior

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.

Environment

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)
Bug

Most helpful comment

Hi @timunie and @punker76,

I made the sample repro public.

Thanks again for your effort!

Best regards,
Gordon

All 7 comments

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

@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

Was this page helpful?
0 / 5 - 0 ratings