Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Another thing that you can do is implement <code>DataTrigger</code> for <code>Grid</code> which will override default <code>MouseLeave</code> and <code>MouseEnter</code> events to do nothing when <code>DisableTriggers</code> property changed.</p> <pre><code> &lt;Style TargetType="{x:Type Grid}"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding DisableTriggers}" Value="True"&gt; &lt;Setter Property="Style" Value="{StaticResource GridStyleWithoutStoryboards}" /&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p>This is the case when you don't want to use <code>AttachedBehaviors</code>. Otherwise I suggest to handle storyboards cleanup in behavior. It is much easier:</p> <pre><code>void OnDisableTriggersPropertyChanged( object sender, EventArgs args ) { // If IsDisposed property was changed and it is true now - cleanup triggers. if ((bool)args.NewValue) { var grid = (Grid)sender; // Ideally you can remove specific triggers. // Clear all will work for simple cases. grid.Triggers.Clear(); } } </code></pre> <p>So summing up you will have to add attached behavior with <code>DisableTriggers</code> dependency property which performs cleanup action in <code>OnChanged</code> handler.</p> <p>If you want to unsubscribe only from specific events:</p> <pre><code> foreach (var eventToUnsubscribe in grid.Triggers.OfType&lt;EventTrigger&gt;() .Where(x =&gt; x.RoutedEvent == UIElement.MouseEnterEvent || x.RoutedEvent == UIElement.MouseLeaveEvent).ToList()) { grid.Triggers.Remove(eventToUnsubscribe); }; </code></pre>
    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.
    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