views:

167

answers:

2

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?

A: 

Try changing the name of your static resource.

Serg
+1  A: 

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!

Yacoder
Yep, that sounds exactly like what's happening.
Jonathan Allen