Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 372947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:15:37+00:00 2026-05-12T14:15:37+00:00

I have the following style: <Style x:Key=ActionLabelStyle TargetType={x:Type Label}> <Setter Property=Margin Value=10,3 /> <Setter

  • 0

I have the following style:

<Style x:Key="ActionLabelStyle" TargetType="{x:Type Label}">
    <Setter Property="Margin" Value="10,3" />
    <Setter Property="Padding" Value="0" />
    <Setter Property="TextBlock.TextWrapping" Value="Wrap" />
    <Setter Property="FontFamily" Value="Calibri" />
    <Style.Triggers>
        <MultiTrigger>
            <MultiTrigger.Conditions>
                <Condition Property="IsMouseOver" Value="True" />
                <Condition Property="IsEnabled" Value="True" />
            </MultiTrigger.Conditions>
            <Setter Property="Background" Value="Red" />
            <Setter Property="TextBlock.TextDecorations" Value="Underline" />
        </MultiTrigger>
    </Style.Triggers>
</Style>

So basically, I want to have a label which is underlined when it is enabled and the mouse cursor is over it. The part of this style which is not working is the <Setter Property="TextBlock.TextDecorations" Value="Underline" />. Now, what am I doing wrong here? Thanks for all the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:15:37+00:00Added an answer on May 12, 2026 at 2:15 pm

    This is actually much more difficult than it appears. In WPF, a Label is not a TextBlock. It derives from ContentControl and can therefore host other, non-text controls in its Content collection.

    However, you can specify a string as the content as in the example below. Internally, a TextBlock will be constructed to host the text for you.

    <Label Content="Test!"/>
    

    This internally translates to:

        <Label>
            <Label.Content>
                <TextBlock>
                    Test!
                </TextBlock>
            </Label.Content>
        </Label>
    

    The simple solution to this would be for the TextDecorations property of a TextBlock to be an attached property. For example, FontSize is designed this way, so the following works:

        <Label TextBlock.FontSize="24">
            <Label.Content>
                <TextBlock>
                    Test!
                </TextBlock>
            </Label.Content>
        </Label>
    

    The TextBlock.FontSize attached property can be applied anywhere in the visual tree and will override the default value for that property on any TextBlock descendant in the tree. However, the TextDecorations property is not designed this way.

    This leaves you with at least a few options.

    1. Use color, border, cursor, etc., instead of underlined text because this is 100% easier to implement.
    2. Change the way you are doing this to apply the Style to the TextBlock instead.
    3. Go to the trouble to create your own attached property and the control template to respect it.
    4. Do something like the following to nest the style for TextBlocks that appear as children of your style:

    FYI, this is the ugliest thing I’ve done in WPF so far, but it works!

        <Style x:Key="ActionLabelStyle" TargetType="{x:Type Label}">
            <Setter Property="Margin" Value="10,3" />
            <Setter Property="Padding" Value="0" />
            <Setter Property="TextBlock.TextWrapping" Value="Wrap" />
            <Setter Property="FontFamily" Value="Calibri" />
            <Style.Triggers>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsMouseOver" Value="True" />
                        <Condition Property="IsEnabled" Value="True" />
                    </MultiTrigger.Conditions>
                    <Setter Property="Background" Value="Red" />
                </MultiTrigger>
            </Style.Triggers>
            <Style.Resources>
                <Style TargetType="TextBlock">
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Label}, Path=IsMouseOver}" Value="True" />
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" Value="True" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="TextDecorations" Value="Underline"/>
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </Style.Resources>
        </Style>
    

    This works because it is overriding the default style of any TextBlock beneath a Label of this style. It then uses a MultiDataTrigger to allow relative binding back up to the Label to check if its IsMouseOver property is True. Yuck.

    Edit:

    Note that this only works if you explicitly create the TextBlock. I was incorrect when I posted this because I had already dirtied up my test Label. Boo. Thanks, Anvaka, for pointing this out.

        <Label Style="{StaticResource ActionLabelStyle}">
            <TextBlock>Test!</TextBlock>
        </Label>
    

    This works, but if you have to go to this trouble, you’re just working too hard. Either someone will post something more clever, or as you said, my option 1 is looking pretty good right now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following user control: <UserControl.Resources> <Style TargetType=HeaderedItemsControl> <Setter Property=Template> <Setter.Value> <ControlTemplate TargetType=HeaderedItemsControl> <Grid>
I have a span with the following style: margin: 5px 0; padding: 2px; cursor:
In .NET WPF, I have the following XAML code: <StackPanel> <StackPanel.Resources> <Style TargetType=FrameworkElement> <Setter
Assume I have the following style table, col1 col2 and col3 have same value
The Scenario: i have in web.config in appSettings a key: <add key=stylet value=http://localhost/style.css/> i
I have the following style for my footers in my css file: #footer {
I have the following style defined which is being applied (as text changes to
So I have come up with the following style sheet in jsfiddle http://jsfiddle.net/8FNZE/2/ and
I find that I have to use the following style to specify a style
I have the following CSS .ul{ list-style-image:url(/images/bullet.png) } My bullet.png is 20 x 20px

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.