Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freeze exception on DropShadowEffect when opening a contextmenu #3935

Closed
gordon771 opened this issue Oct 12, 2020 · 7 comments · Fixed by #3941
Closed

Freeze exception on DropShadowEffect when opening a contextmenu #3935

gordon771 opened this issue Oct 12, 2020 · 7 comments · Fixed by #3941
Assignees
Labels
Milestone

Comments

@gordon771
Copy link

gordon771 commented Oct 12, 2020

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)
@gordon771 gordon771 added the Bug label Oct 12, 2020
@timunie
Copy link
Collaborator

timunie commented Oct 12, 2020

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

@gordon771
Copy link
Author

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

@timunie
Copy link
Collaborator

timunie commented Oct 13, 2020

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

@gordon771
Copy link
Author

Hi @timunie and @punker76,

I made the sample repro public.

Thanks again for your effort!

Best regards,
Gordon

@timunie
Copy link
Collaborator

timunie commented Oct 14, 2020

and here is the link: https://github.com/gordon771/MahAppsTest

@punker76 punker76 added this to the 2.3.0 milestone Oct 14, 2020
@punker76 punker76 self-assigned this Oct 14, 2020
@punker76
Copy link
Member

punker76 commented Oct 18, 2020

@gordon771 I created a PR at your test project gordon771/MahAppsTest#2

If you want to use WPF windows in different threads then it's necessary to add the MahApps resources to each window.

@gordon771
Copy link
Author

Hi @punker76 ,

okay, that was my workaround so far.

Thank you for your answer and your effort!

Best regards,
Gordon

punker76 added a commit that referenced this issue Oct 21, 2020
Introduce shadow key
- MahApps.DropShadowEffect.Menu
- MahApps.DropShadowEffect.Menu.VisualStudio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants