I have the following triggers in a custom button style:
<Trigger Property="IsEnabled" Value="true"> <Setter Property="BorderBrush" Value="#FFFFFFFF" /> <Setter Property="Foreground" Value="#FFFFFFFF" /> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="BorderBrush" Value="#FFFF9800" /> <Setter Property="Foreground" Value="#FFFF9800" /> </Trigger> But they don't apply in my GUI at all. Below is the entire Style.
<Window.Resources> <Style x:Key="Button.Hoverless" TargetType="{x:Type ButtonBase}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ButtonBase}"> <Border Name="border" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" /> </Border> <ControlTemplate.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True" /> <Condition Property="Selector.IsSelected" Value="False" /> </MultiTrigger.Conditions> <Setter Property="Background" Value="#FFFF9800" /> <Setter Property="Opacity" Value="0.50" /> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True" /> <Condition Property="Selector.IsSelected" Value="True" /> </MultiTrigger.Conditions> <Setter Property="Background" Value="#FFFFB850" /> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="False" /> <Condition Property="Selector.IsSelected" Value="True" /> </MultiTrigger.Conditions> <Setter Property="Background" Value="#FFFF9800" /> </MultiTrigger> <Trigger Property="IsEnabled" Value="true"> <Setter Property="BorderBrush" Value="#FFFFFFFF" /> <Setter Property="Foreground" Value="#FFFFFFFF" /> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="BorderBrush" Value="#FFFF9800" /> <Setter Property="Foreground" Value="#FFFF9800" /> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="border" Property="Opacity" Value="0.95" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> I'm new to WPF styling and thus I'm not sure where I went wrong with this. Also included is the button code:
<Button x:Name="btnScanFP1" Content="Scan Fingerprint" Grid.Column="1" HorizontalAlignment="Left" Margin="10,10,0,0" Grid.Row="4" VerticalAlignment="Top" Width="227" Height="21" Grid.ColumnSpan="2" FontSize="11" Click="btnScanFP1_Click" Background="{x:Null}" BorderBrush="#FFFF9800" Foreground="#FFFF9800" Style="{StaticResource Button.Hoverless}"/>
Button.Hoverlesswhich is of type of DottedXamlName. This type of specification is used for property and event qualified references, and also for attached members. So remove the . from your key name.Style="{StaticResource ResourceKeyName}". If you want to apply to all buttons then remove the key attribute.#FFFF9800, which has a higher priority than the setters in your style's triggers. UsingButtonbaseasTargetTypeis perhaps a bit odd but shouldn't be a problem, asButtoninherits fromButtonBase.