开发者

How can I add bold text and AccessText to a Label or TextBlock?

I have a WPF conundrum. I want some text to look like this:

Enter this preparer's info: [ComboBox]

Alt+E is the access key that focuses the ComboBox, and when Alt is pressed, the E in the text should be underlined.

I can get the access key to work easily:

<Label Target="{Binding ElementName=PreparerComboBox}">
    _Enter this preparer's info:</Label>

But then "preparer's" can't be bold because a Label doesn't support Runs (as far as I c开发者_Go百科an tell).

I can do the bolding easily in a TextBlock:

<TextBlock>Enter this <Bold>preparer's</Bold> info:</TextBlock>

But there's no access key defined, so I tried adding my AccessText inside the TextBlock:

<Label Target="{Binding ElementName=PreparerComboBox}">
    <TextBlock>
        <AccessText>_Enter</AccessText> this <Bold>preparer's</Bold> info:
    </TextBlock>
</Label>

But then the AccessText doesn't line up properly with the rest of the text in the TextBlock, and Margin doesn't seem to have any effect on it.

Example:

How can I add bold text and AccessText to a Label or TextBlock?

The best I've come up with so far is this monstrosity:

<Label Target="{Binding ElementName=PreparerComboBox}">
    <WrapPanel>
        <AccessText>_E</AccessText>
        <TextBlock>nter this <Bold>preparer's</Bold> info:</TextBlock>
    </WrapPanel>
</Label>

What am I missing here? Seems like there has to be an easier way.


Didn't change much but how about

<Label Target="{Binding ElementName=PreparerComboBox}">
    <StackPanel Orientation="Horizontal">
        <AccessText>_Enter</AccessText>
        <TextBlock xml:space="preserve"> this <Bold>preparer's</Bold> info:</TextBlock>
    </StackPanel>
</Label>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜