tags:

views:

36

answers:

1

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 can 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.

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.

+1  A: 

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>
Meleak