Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to highlight a button in XAML using Triggers?
    primarykey
    data
    text
    <p>I have an ItemsControl control that displays some buttons. When I click on one of the buttons I have to show some details of the selected resource (bound to the button).</p> <p>So when the button is clicked I set a property on the ViewModel called SelectedResource.</p> <p>That's working fine, what I'd like to do is to highlight the button clicked.</p> <p>I have a ControlTemplate for my button as follows:</p> <pre><code>&lt;ControlTemplate x:Key="ResourceButtonTemplate" TargetType="{x:Type ButtonBase}"&gt; &lt;Border Name="SelectedButtonBorder" CornerRadius="3"&gt; &lt;Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3" Background="{TemplateBinding Background}" SnapsToDevicePixels="True"&gt; &lt;StackPanel Orientation="Horizontal" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"&gt; &lt;Image Source="{Binding Type.Value, Converter={converter:ResourceTypeToStringConverter}}"&gt;&lt;/Image&gt; &lt;ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/&gt; &lt;/StackPanel&gt; &lt;/Border&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;DataTrigger Binding="{Binding SelectedResource}" Value=""&gt; &lt;Setter TargetName="SelectedButtonBorder" Property="BorderBrush" Value="Red" /&gt; &lt;Setter TargetName="SelectedButtonBorder" Property="BorderThickness" Value="2" /&gt; &lt;/DataTrigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; </code></pre> <p>I've tried the DataTrigger, but I can't bind the value property of the datatrigger.</p> <p>So, is there a way to do that using only XAML?</p> <p><strong>Edit:</strong></p> <p>I don't want to compare the SelectedResource to an empty string, I actually don't know what to compare to. I tried to compare one of the properties of the SelectedResource object to the text shown on the button.</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.
 

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