Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a really, really annoying problem in WPF. I'd go so far as to call it a bug.</p> <p>As @levanovd mentioned in his answer, you can get a hyperlink to wrap properly by using a <code>Run</code> as the inner element:</p> <pre><code> &lt;StackPanel&gt; &lt;TextBlock TextWrapping="Wrap"&gt; &lt;Hyperlink&gt;&lt;Run&gt;This is a really long hyperlink. Yeah, a really really long hyperlink, whaddaya think?&lt;/Run&gt;&lt;/Hyperlink&gt; &lt;/TextBlock&gt; &lt;/StackPanel&gt; </code></pre> <p>This works great, until you want to apply text formatting <em>within</em> the hyperlink. If you tried to do this, for example:</p> <pre><code> &lt;StackPanel&gt; &lt;TextBlock TextWrapping="Wrap"&gt; &lt;Hyperlink&gt;&lt;Run&gt;This is a really long &lt;Run TextWeight="Bold"&gt;hyperlink&lt;/Run&gt;. Yeah, a really really long hyperlink, whaddaya think?&lt;/Run&gt;&lt;/Hyperlink&gt; &lt;/TextBlock&gt; &lt;/StackPanel&gt; </code></pre> <p>You'd get a compile error: </p> <blockquote> <p>The object 'Run' already has a child and cannot add ''. 'Run' can accept only one child.</p> </blockquote> <p>So, as @Scott Whitlock noted, you have to use a <code>TextBlock</code> as the inner element and mess around with the <code>TextDecoration</code> attributes of the <code>Hyperlink</code> and <code>TextBlock</code> instead:</p> <pre><code> &lt;StackPanel&gt; &lt;TextBlock&gt; &lt;Hyperlink TextDecorations="None"&gt;&lt;TextBlock TextWrapping="Wrap" TextDecorations="Underline"&gt;This is a really long &lt;Run FontWeight="Bold"&gt;hyperlink&lt;/Run&gt;. Yeah, a really really long hyperlink, whaddaya think?&lt;/TextBlock&gt;&lt;/Hyperlink&gt; &lt;/TextBlock&gt; &lt;/StackPanel&gt; </code></pre> <p>Sigh. I really hate WPF's <code>Hyperlink</code> element. It just doesn't work anything like you'd expect.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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