Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Quote from <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx" rel="nofollow">MSDN</a>:</p> <blockquote> <p>Important</p> <p>RichTextBox has built-in handling for the bubbling MouseUp and MouseDown events. Consequently, custom event handlers that listen for MouseUp or MouseDown events from a RichTextBox will never be called. If you need to respond to these events, listen for the tunneling PreviewMouseUp and PreviewMouseDown events instead, or register the handlers with the HandledEventsToo argument (this latter option is only available through code). Do not mark the event handled unless you deliberately want to disable RichTextBox native handling of these events, and be aware that this has notable effects on the control's UI.</p> </blockquote> <p>So you need to look for alternatives. I can suggest a few.</p> <p>First, you can set an event handler <code>PreviewMouseDown</code> for all <code>RichTextBox</code>:</p> <pre><code>&lt;RichTextBox PreviewMouseDown="TextBlock_Click" ... /&gt; </code></pre> <p>Second, use the <code>BlockUIContainer</code> and put the text in the content button. For example:</p> <pre><code>&lt;Paragraph FontSize="18"&gt;Flow Example&lt;/Paragraph&gt; &lt;BlockUIContainer&gt; &lt;Button x:Name="MyButton" ClickMode="Release" Click="Button_Click"&gt; &lt;TextBlock Margin="4" TextWrapping="Wrap"&gt; Some text &lt;/TextBlock&gt; &lt;/Button&gt; &lt;/BlockUIContainer&gt; </code></pre> <p>Third, you can set the event handler for the <code>Paragraph</code> like that:</p> <pre><code>var para = new Paragraph(); para.Inlines.Add(textBlock1); para.MouseLeftButtonDown += new MouseButtonEventHandler(TextBlock_Click); </code></pre> <p><strong><code>Edit</code></strong></p> <p>Quote from Adam Nathan's book <code>WPF 4 Unleashed</code>:</p> <blockquote> <p>Whereas TextBox exposes simple integer properties such as CaretIndex, SelectionStart, and SelectionEnd, RichTextBox exposes a CaretPosition property of type TextPointer and a Selection property of type TextSelection. In addition, RichTextBox’s content is stored in a Document property of type FlowDocument rather than the simple string Text property. The content can even contain embedded UIElements, and they can be interactive and raise events if RichTextBox’s IsDocumentEnabled property is set to true.</p> </blockquote> <p>Events began to work, it is necessary to add <code>BlockUIContainer</code> with <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.isdocumentenabled.aspx" rel="nofollow"><code>IsDocumentEnabled</code></a> property is set to <em><code>true</code></em> (in <code>RichTextBox</code>), otherwise, the event will not working altogether. </p> <p>In general, I do not understand why you need it <code>TextBlock</code> inside <code>RichTextBox</code>. Use it the standard features, they pretty much cover, those <code>Run</code>, <code>Paragraph</code>, etc. If they do not match, then there is no reason to use <code>RichTextBox</code>.</p> <p>See the nice tutorial about <code>RichTextBox</code> <a href="http://msdn.microsoft.com/en-us/library/ee681613%28v=vs.95%29.aspx" rel="nofollow">here</a>.</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.
    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