3

When I add this style, it breaks my application with a StackOverflowException.

<Style TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}" >
<!-- <Setter Property="Background" Value="{DynamicResource WindowBackgroundBrush}" /> -->
</Style>

In case it matters, I'm using the ShinyBlue theme.

Any ideas what would cause this?

4
  • Could you elaborate this a little more? I just created an empty WPF project and copy/pasted your code, added a GroupBox and it works fine. Do you have trouble in the IDE also, or only when starting? Debug or release compile? Which VS version are you using? SP1 installed? Operating system? Commented Feb 5, 2010 at 0:32
  • VS 2008 SP1. Debug mode. It works in XAMLPad. Commented Feb 5, 2010 at 0:35
  • Hm, just like my setup, running on Win 7. Perhaps you could post some more code in which environment this is used. I simply put it into a Windows.Resources section where it works fine. Did you try that with a minimal example? Commented Feb 5, 2010 at 0:42
  • It doesn't happen with a minimal example. Maybe it has to do with the fact that I'm loading it into a WinForms form. Commented Feb 5, 2010 at 0:50

2 Answers 2

2

That's kind of a "known issue", at least I remember I had it too and it reproduces with styles based on default styles for controls which also have some default styles in the theme. AFAIR, I used my own theme, so I just went and gave names to those styles and used the names instead of the {x:Type GroupBox} and it helped me, but if you can't do this, the Internets advise you to move your derived styles to a lower XAML scope.

As for the root cause of the exception, AFAIR, there is a bug in the default style resolution, which takes theme's style as the default for your custom style and then takes your custom style as the default for the theme's one and so on, so forth, SO!

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, that sounds exactly like what's happening.
1

Try changing the name of your static resource.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.