WPF:为什么这会导致堆栈溢出异常?
当我添加此样式时,它会因 StackOverflowException 中断我的应用程序。
<Style TargetType="GroupBox" BasedOn="{StaticResource {x:Type GroupBox}}" >
<!-- <Setter Property="Background" Value="{DynamicResource WindowBackgroundBrush}" /> -->
</Style>
如果重要的话,我使用的是 ShinyBlue 主题。
有什么想法会导致这种情况吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一种“已知问题”,至少我记得我也遇到过它,并且它使用基于控件默认样式的样式进行再现,这些控件在主题中也有一些默认样式。 AFAIR,我使用了自己的主题,所以我只是给这些样式命名并使用名称而不是
{x:Type GroupBox}
这对我有帮助,但如果你不能这样做这个,互联网建议< /a> 您将派生样式移至较低的 XAML 范围。至于异常的根本原因,AFAIR,默认样式解析有一个bug,它把主题的样式作为你自定义样式的默认样式,然后把你自定义的样式作为主题的默认样式等等,所以向前,所以!
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!
尝试更改静态资源的名称。
Try changing the name of your static resource.