Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If using a <code>Label</code> or a <code>Hyperlink</code> won't work in your situation, you could take the approach of a creating a new derived <code>TextBlock</code> that simply defines a new <code>DoubleClick</code> routed event which bubbles up through the tree:</p> <pre><code>public class ClickableTextBlock : TextBlock { #region Overrides protected override void OnMouseLeftButtonDown(System.Windows.Input.MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); if (e.ClickCount == 2) { RaiseEvent(new RoutedEventArgs(DoubleClickEvent, this)); } } #endregion #region DoubleClick RoutedEvent public static readonly RoutedEvent DoubleClickEvent = EventManager.RegisterRoutedEvent("DoubleClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(ClickableTextBlock)); public event RoutedEventHandler DoubleClick { add { AddHandler(DoubleClickEvent, value); } remove { RemoveHandler(DoubleClickEvent, value); } } #endregion } </code></pre> <p>This control can be used in the same way as your standard <code>TextBlock</code>. In this example, double clicking on the <code>TextBlock</code> will raise the <code>DoubleClick</code> event which is then acted upon by the parent <code>StackPanel</code> to start an animation:</p> <pre><code>&lt;StackPanel x:Name="myStackPanel" Background="LightGreen"&gt; &lt;StackPanel.Triggers&gt; &lt;EventTrigger RoutedEvent="l:ClickableTextBlock.DoubleClick"&gt; &lt;BeginStoryboard&gt; &lt;Storyboard&gt; &lt;DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:1" To="0.5" FillBehavior="Stop"/&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/EventTrigger&gt; &lt;/StackPanel.Triggers&gt; &lt;l:ClickableTextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Background="LightPink" Text="Double Click to change parent's opacity" /&gt; &lt;/StackPanel&gt; </code></pre> <p>Hope this helps!</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. 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