Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I underline a single character in the Content of a Button in WPF?

I have a number of buttons in my WPF window and I would like to have certain characters in the button contents underlined.

I have tried using the "_" like "My_Content" to underline the C, however this does not appear until the user hits the Alt key, or has their local settings changed. Using < Underline > within the Content property causes an error when I attempt to underline only part of the content like:

Content="My< Underline >C< /Underline >ontent".

I would prefer to set this in the XAML if possible. Any help would be appreciated.

Thank You!

like image 576
MtnDew Avatar asked May 20 '11 17:05

MtnDew


1 Answers

You would have to do this explicitly like so:

<Button>
    <Button.Content>
        <TextBlock>
            My <Underline>C</Underline>ontent
        </TextBlock>
    </Button.Content>
</Button>

This would remove the ability to click the button using Alt+Char though. For that an AccessText element is used. But that doesn't support the markup syntax of TextBlock.

like image 166
CodeNaked Avatar answered Oct 24 '22 17:10

CodeNaked