Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Why would this cause a stack overflow exception?

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?

like image 381
Jonathan Allen Avatar asked May 25 '26 14:05

Jonathan Allen


1 Answers

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!

like image 117
Max Galkin Avatar answered May 27 '26 05:05

Max Galkin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!