currently i am forcing my WPF app to use the luna theme no matter what, with this XAML code
目前我正在强迫我的WPF应用程序使用luna主题,无论如何,使用此XAML代码
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Styles.xaml" />
<ResourceDictionary Source="NavigationCommands.xaml" />
<ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;;component/Themes/luna.normalcolor.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
and now i want to extend the style of every textbox with this validation trigger
现在我想用这个验证触发器扩展每个文本框的样式
<Style TargetType="TextBox">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="Background" Value="#d3e1f3"></Setter>
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
but this trigger does not work, because i forced the luna theme. (without the forced theme every thing works as it should, but doesn't look as it should :( ) is there some way to force the luna theme and extend it's style? probably over the BasedOn property?
但是这个触发器不起作用,因为我强迫了luna主题。 (没有强制主题,每个东西都应该工作,但看起来不应该:()是否有某种方法来强制luna主题并扩展它的样式?可能在BasedOn属性上?
atm i defined a key for the style in question and added it to every textbox by hand, that works but isn't the prettiest way to go.
atm我为这个风格定义了一个关键字并将其添加到每个文本框中,这样做有效但不是最漂亮的方式。
tia
4 个解决方案
#1
1
Try
<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}">
#2
1
The BasedOn syntax for type styles is as follows:
类型样式的BasedOn语法如下:
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
HTH
#3
0
Have you tried to set the lune resourcedictionary first and your own resourcedictionary last? I can imagine the luna theme overrides your style.
你有没有尝试先设置lune resourcedictionary,最后设置自己的resourcedictionary?我可以想象luna主题会覆盖你的风格。
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;;component/Themes/luna.normalcolor.xaml" />
<ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml"/>
<ResourceDictionary Source="Styles.xaml" />
<ResourceDictionary Source="NavigationCommands.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
#4
0
Use the mentioned
使用上面提到的
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
but also make sure your dictionaries are included in right order - first the ones you are basing your style on
但也要确保你的词典包含在正确的顺序中 - 首先是你的风格基础
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;;component/Themes/luna.normalcolor.xaml" />
<ResourceDictionary Source="Styles.xaml" />
<ResourceDictionary Source="NavigationCommands.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
#1
1
Try
<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}">
#2
1
The BasedOn syntax for type styles is as follows:
类型样式的BasedOn语法如下:
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
HTH
#3
0
Have you tried to set the lune resourcedictionary first and your own resourcedictionary last? I can imagine the luna theme overrides your style.
你有没有尝试先设置lune resourcedictionary,最后设置自己的resourcedictionary?我可以想象luna主题会覆盖你的风格。
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;;component/Themes/luna.normalcolor.xaml" />
<ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml"/>
<ResourceDictionary Source="Styles.xaml" />
<ResourceDictionary Source="NavigationCommands.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
#4
0
Use the mentioned
使用上面提到的
<Style TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
but also make sure your dictionaries are included in right order - first the ones you are basing your style on
但也要确保你的词典包含在正确的顺序中 - 首先是你的风格基础
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml"/>
<ResourceDictionary Source="/PresentationFramework.Luna, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;;component/Themes/luna.normalcolor.xaml" />
<ResourceDictionary Source="Styles.xaml" />
<ResourceDictionary Source="NavigationCommands.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>