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).
So when the button is clicked I set a property on the ViewModel called SelectedResource.
That's working fine, what I'd like to do is to highlight the button clicked.
I have a ControlTemplate for my button as follows:
<ControlTemplate x:Key="ResourceButtonTemplate" TargetType="{x:Type ButtonBase}">
<Border Name="SelectedButtonBorder"
CornerRadius="3">
<Border x:Name="border"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="3"
Background="{TemplateBinding Background}"
SnapsToDevicePixels="True">
<StackPanel Orientation="Horizontal" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
<Image Source="{Binding Type.Value, Converter={converter:ResourceTypeToStringConverter}}"></Image>
<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}"/>
</StackPanel>
</Border>
</Border>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding SelectedResource}" Value="">
<Setter TargetName="SelectedButtonBorder" Property="BorderBrush" Value="Red" />
<Setter TargetName="SelectedButtonBorder" Property="BorderThickness" Value="2" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
I've tried the DataTrigger, but I can't bind the value property of the datatrigger.
So, is there a way to do that using only XAML?
Edit:
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.