Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I add bold text and AccessText to a Label or TextBlock?
    primarykey
    data
    text
    <p>I have a WPF conundrum. I want some text to look like this:</p> <blockquote> <p>Enter this <strong>preparer's</strong> info: [ComboBox]</p> </blockquote> <p>Alt+E is the access key that focuses the ComboBox, and when Alt is pressed, the E in the text should be underlined.</p> <p>I can get the access key to work easily:</p> <pre><code>&lt;Label Target="{Binding ElementName=PreparerComboBox}"&gt; _Enter this preparer's info:&lt;/Label&gt; </code></pre> <p>But then "preparer's" can't be bold because a Label doesn't support Runs (as far as I can tell). </p> <p>I can do the bolding easily in a TextBlock:</p> <pre><code>&lt;TextBlock&gt;Enter this &lt;Bold&gt;preparer's&lt;/Bold&gt; info:&lt;/TextBlock&gt; </code></pre> <p>But there's no access key defined, so I tried adding my AccessText inside the TextBlock:</p> <pre><code>&lt;Label Target="{Binding ElementName=PreparerComboBox}"&gt; &lt;TextBlock&gt; &lt;AccessText&gt;_Enter&lt;/AccessText&gt; this &lt;Bold&gt;preparer's&lt;/Bold&gt; info: &lt;/TextBlock&gt; &lt;/Label&gt; </code></pre> <p>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.</p> <p>Example: <img src="https://i.stack.imgur.com/CPROF.png" alt="alt text"></p> <p>The best I've come up with so far is this <em>monstrosity</em>:</p> <pre><code>&lt;Label Target="{Binding ElementName=PreparerComboBox}"&gt; &lt;WrapPanel&gt; &lt;AccessText&gt;_E&lt;/AccessText&gt; &lt;TextBlock&gt;nter this &lt;Bold&gt;preparer's&lt;/Bold&gt; info:&lt;/TextBlock&gt; &lt;/WrapPanel&gt; &lt;/Label&gt; </code></pre> <p>What am I missing here? Seems like there has to be an easier way.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload