A
A
Alexander Zaitsev2014-08-13 18:39:06
WPF
Alexander Zaitsev, 2014-08-13 18:39:06

How to create a button in WPF, when you hover over it, a horizontal line appears under the text?

In order to create your own button design, you need to write your own control template and assign it to the button. I see 2 implementation options, although each has a BUT that prevents it from being selected
1) Place a TextBlock in the template, add a style to it, a trigger that, on hover, will set the value of the TextDecoration attribute to Underline. Problem - there is no Click event.
2) Place inside ContentPresenter. The TextDecoration attribute is missing.
Could you suggest a way that would help solve the problem without problems?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sumor, 2014-08-14
@Sumor

The following may work as an intermediate solution.

<Button >            
    <Run>
        <Run.Style>
            <Style TargetType="Run">
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="TextDecorations" Value="Underline" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Run.Style>
        Текст
    </Run>
</Button>

V
Vasily Samoilov, 2014-08-14
@Imagio

Perhaps Hyperlink will help:

<TextBlock >
    <Hyperlink Click="Hyperlink_OnClick"></Hyperlink>
</TextBlock>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question