Note that there are some explanatory texts on larger screens.

plurals
  1. POUse a property trigger to change a property that already has a binding
    text
    copied!<p>How can I use a property trigger in a style (or another method) to change a property (ToolTip for example) that already has its value defined by a binding?</p> <p>I have a simple button like so:</p> <pre><code>&lt;Button Name="Button1" Style="{StaticResource ButtonStyle}" ToolTip="{Binding Name}" &gt;My Button&lt;/Button&gt; </code></pre> <p>It has a binding on the tooltip to show the Name property of the class set as DataContext.</p> <p>My problem is I want to show the Name when the button is enabled, but something else when it is disabled. I thought I could get around my problem with a style and a trigger like so:</p> <pre><code>&lt;Style TargetType="Button" x:Key="ButtonStyle"&gt; &lt;Setter Property="ToolTipService.ShowOnDisabled" Value="True" /&gt; &lt;Style.Triggers&gt; &lt;Trigger Property="IsEnabled" Value="false"&gt; &lt;Setter Property="ToolTip" Value="Disabled" /&gt; &lt;/Trigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p>But this doesn't work. If I removed the tooltip binding from the button then I do get the correct tooltip when the button is disabled. But it seems I can't have both a binding and a trigger on the same property.</p> <p>I could get around it by adding another trigger like so:</p> <pre><code>&lt;Trigger Property="IsEnabled" Value="true"&gt; &lt;Setter Property="ToolTip" Value="{Binding Name}" /&gt; &lt;/Trigger&gt; </code></pre> <p>But I would like to use the style for 4 or 5 buttons that will all have different bindings for the enabled ToolTip, but the same (fixed) tooltip when they are disabled.</p> <p>Any suggestions?</p>
 

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