在WPF的TextBox覆盖默认样式的基础上,PresentationFramework.Aero
题
我想使用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,这工作,但我得到了默认的操作系统的造型,这使得应用难看。 ;)
所以,在效果:如果我要重写我的所有文本框的一些风格,我不能获得航空的外观。如果我想航空看,我不能重写任何样式。死锁。
要解决这个任何方式?
解决方案
看来,如果你在同一个ResourceDictionary中提出,而不是作为Style
较低水平的资源,工作:
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero, Version=3.0.0.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;component/themes/aero.normalcolor.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Grid.Resources>
<Border BorderBrush="Blue" BorderThickness="3">
<Border.Resources>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Setter Property="Margin" Value="2" />
<Setter Property="Padding" Value="2" />
</Style>
</Border.Resources>
<TextBox />
</Border>
</Grid>
其他提示
不同于接受的答案代码可将该一个允许使用资源字典样式。 //social.msdn:从 HTTP无耻地窃取。 microsoft.com/forums/en-US/wpf/thread/3c66adb7-fd26-40c7-8404-85f6fefbd392/ 通过回答费雯丽吕伊斯
<!--App.xaml-->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MyAppli;component/Resources/Themes/StyleDictionary.xaml"/>
<ResourceDictionary Source="/MyAppli;component/Resources/Themes/ApplyStyleDictionary.xaml"/>
...
</ResourceDictionary.MergedDictionaries>
<!--StyleDictionary.xaml-->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component/themes/aero.normalcolor.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="ButtonStyleToApply" TargetType="Button" BasedOn="{StaticResource {x:Type Button}}" >
... <!--Extend the aero style here-->
</Style>
<!--ApplyStyleDictionary.xaml-->
<Style TargetType="Button" BasedOn="{StaticResource ButtonStyleToApply}"/>
不隶属于 StackOverflow