基于PresentationFramework.Aero 覆盖WPF TextBox 中的默认样式
我想使用 Aero 文本框样式,但仍然覆盖一些属性。 我尝试通过以下方式实现此目的:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Margin" Value="2" />
<Setter Property="Padding" Value="2" />
</Style>
</ResourceDictionary>
但是,这会在启动我的应用程序时导致 StackOverflowException 。 当我删除对PresentationFramework.Aero的引用时,这可以工作,但我得到了默认的操作系统样式,这使得应用程序变得丑陋。 ;)
所以,实际上:如果我想覆盖所有文本框上的某些样式,我无法获得 Aero 外观。 如果我想要 Aero 外观,我无法覆盖任何样式。 僵局。
有办法解决这个问题吗?
I want to use the Aero textbox styling, but still override some properties. I try to accomplish this by:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Margin" Value="2" />
<Setter Property="Padding" Value="2" />
</Style>
</ResourceDictionary>
However, this results in a StackOverflowException
when starting my app.
When I remove the reference to PresentationFramework.Aero, this works but I get the default OS styling, which makes the app ugly. ;)
So, in effect: if I want to override some style on all my textboxes I cannot get the Aero look. If I want the Aero look, I cannot override any styling. Deadlock.
Any way to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果将
Style
作为较低级别的资源,而不是放在同一个 ResourceDictionary 中,它似乎可以工作:It seems to work if you put the
Style
as a lower-level resource, instead of in the same ResourceDictionary:与接受的答案中的代码不同,此代码允许使用资源字典作为样式。 无耻地从 http://social.msdn 窃取。 microsoft.com/forums/en-US/wpf/thread/3c66adb7-fd26-40c7-8404-85f6fefbd392/由Vivien Ruitz回答
Unlike the code in accepted answer this one allows using resource dictionary for styles. Shamelessly stolen from http://social.msdn.microsoft.com/forums/en-US/wpf/thread/3c66adb7-fd26-40c7-8404-85f6fefbd392/ answered by Vivien Ruitz