问题
If you set OverridesDefaultStyle
to true, the default style won't be used.
What is the result of using BasedOn
at the same time?
<Style x:Key="MenuButton" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
TargetType="{x:Type c:MenuButton}">
<Setter Property="OverridesDefaultStyle" Value="True" />
</Style>
Do the two instructions contradict each other in any way?
Is it the default style underlying ToolBar.ButtonStyleKey
that will be ignored?
In this particular example I don't see any difference whether OverridesDefaultStyle
is true or false.
回答1:
If you were to use both of those properties, you would end up with a MenuButton
object (in your example) that takes all of its Style
information from your MenuButton
Style
and the remainder of the properties would come from your ToolBar.ButtonStyleKey
Style
. At least, that is true in theory, as I've never actually had to use that arrangement.
In particular, setting the OverridesDefaultStyle
property to True
is 'supposed' to make the styled element not use theme style properties, instead getting all of its Style
values from local application styles. However, I have also found that in some instances, setting this property to True
does not seem to make any difference.
On the other hand, when this property setting does work, it will remove the default ControlTemplate
and so to support the same features as the default theme styles, you must supply an alternate style with a control template that replicates the same structure.
Italic text comes from the FrameworkElement.OverridesDefaultStyle Property page on MSDN
来源:https://stackoverflow.com/questions/19383347/overridesdefaultstyle-together-with-basedon-in-wpf