Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

XAML MultiDataTriggers for 'IsFocused' AND 'IsMouseOver' for a ControlTemplate

$
0
0

Hello, and many thanks, to whomever can help me.

I've created a Style called 'SimpleButton' as a ControlTemplate override for buttons. I am setting the border thickness to 5pix, and setting the Foreground to white upon "IsMouseOver" and "IsFocused".

I can achieve this using two sets of triggers (one for IsFocused and one for IsMouseOver) with redundant setters. But, I'd very much like to avoid the redundancy and use MultiDataTriggers to group IsFocused and IsMouseOver together.

Here is the way I'm doing it now, which works. Notice the redundant seters for buttonBorder and Foreground:

<!--This works swimmingly--><Style x:Key="SimpleButton1" TargetType="Button"><Setter Property="OverridesDefaultStyle" Value="True" /><Setter Property="Margin" Value="5" /><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Button"><Border Name="buttonBorder"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="3"><ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" /></Border><ControlTemplate.Triggers><Trigger Property="IsFocused" Value="True"><Setter TargetName="buttonBorder" Property="BorderThickness" Value="5" /><Setter Property="Foreground" Value="White" /></Trigger><Trigger Property="IsMouseOver" Value="True"><!-- Booh I have to repeat these two setters when I just want to group the IsMouseOver with the IsFocused trigger.--><Setter TargetName="buttonBorder" Property="BorderThickness" Value="5" /><Setter Property="Foreground" Value="White" /></Trigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>

Here was my failed attempt at using MultiDataTriggers. Even though this doesn't work, I hope it conveys my intent enough for someone to help me out:

<!-- This doesn't work with the MultiDataTriggers, syntax is probably wrong--><Style x:Key="SimpleButton2" TargetType="Button"><Setter Property="OverridesDefaultStyle" Value="True" /><Setter Property="Margin" Value="5" /><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Button"><Border Name="buttonBorder"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="3"><ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" /></Border><ControlTemplate.Triggers><MultiDataTrigger><MultiDataTrigger.Conditions><!-- I have a feeling these bindings aren't correct...--><Condition Binding="{Binding IsFocused}" Value="True" /><Condition Binding="{Binding IsMouseOver}" Value="True" /></MultiDataTrigger.Conditions><Setter TargetName="buttonBorder" Property="BorderThickness" Value="5" /><Setter Property="Foreground" Value="White" /></MultiDataTrigger> </ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>

Help is much appreciated.

Thank you.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>