How can I stop ToolTips from inheriting my TextBlock style?

286 views Asked by At

I've defined a style within my application resources that I want all of my textblocks to inerit :

<Style TargetType="{x:Type TextBlock}">
    <Setter Property="Effect">
        <Setter.Value>
            <DropShadowEffect BlurRadius="1" ShadowDepth="0" />
        </Setter.Value>
    </Setter>
    <Setter Property="Foreground" Value="White" />
    <Setter Property="FontFamily" Value="Arial" />
    <Setter Property="FontWeight" Value="Bold" />
</Style>

I don't want to have to go through and explicitly dictate the style on each textblock - I just want all of them to inherit this style naturally.

Unfortunately, when I define a tooltip, that tooltip also picks up this style. I'm guessing it's because the thing incorporates a TextBlock somewhere in it's design.

What I AM okay with is having to go through and style each defined tooltip ( since they are used less ubiquitously throughout my application ), so if there's some way to define a tooltip style that will override the inherited textblock style, I'm fine with that.

So, what can I do to stop my tooltips from inheriting the TextBlock style?

1

There are 1 answers

0
15ee8f99-57ff-4f92-890c-b56153 On BEST ANSWER

It's a terrible idea to set a global implicit style on TextBlock, and this is why. TextBlock is the primitive that displays text. It's much better to set the implicit TextBlock style only where it's needed, not universally.

Or consider using Label instead of TextBlock for the styled text instances, and have an implicit Label style. That's one reason why Label exists. You can style the padding/margin etc. to make it look exactly the way you want.