I have a number of buttons in my WPF window and I would like to have certain characters in the button contents underlined.
我的WPF窗口中有许多按钮,我希望按钮内容中的某些字符带下划线。
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:
我尝试使用像“My_Content”这样的“_”来强调C,但是直到用户点击Alt键或者更改了本地设置才会出现这种情况。当我尝试仅为部分内容加下划线时,在Content属性中使用
Content="My< Underline >C< /Underline >ontent".
Content =“我的
I would prefer to set this in the XAML if possible. Any help would be appreciated.
如果可能的话,我宁愿在XAML中设置它。任何帮助,将不胜感激。
Thank You!
1 个解决方案
#1
10
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.
这将删除使用Alt + Char单击按钮的功能。为此,使用AccessText元素。但是这不支持TextBlock的标记语法。
#1
10
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.
这将删除使用Alt + Char单击按钮的功能。为此,使用AccessText元素。但是这不支持TextBlock的标记语法。