I have the following control template defined as a resource in my user control:
<UserControl.Resources>
<ControlTemplate x:Key="NotificationToggleButtonTemplate" TargetType="{x:Type wpfSupport:NotificationToggleButton}">
<Border Name="Border" CornerRadius="15" Padding="2" BorderThickness="2">
<dxlc:LayoutItem HorizontalAlignment="Center" VerticalAlignment="Center">
<Label FontWeight="Bold" FontSize="12" Padding="0" Margin="0"
Content="{Binding
Path=GetCounters.PendingDocumentRequests,Mode=OneWay}" />
</dxlc:LayoutItem>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsChecked" Value="False"/>
<Condition Property="IsMouseOver" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=(wpfSupport:NotificationToggleButton.ActiveButtonColour)}" />
<Setter Property="BorderBrush" TargetName="Border" Value="Transparent"/>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
I have created a ToggleButton descendant:
public class NotificationToggleButton : ToggleButton
{
public static readonly DependencyProperty ActiveButtonColourProperty =
DependencyProperty.RegisterAttached("ActiveButtonColour", typeof(Brush), typeof(NotificationToggleButton),
new FrameworkPropertyMetadata(Brushes.Black));
public static Brush GetActiveButtonColour(DependencyObject target) => (Brush) target.GetValue(ActiveButtonColourProperty);
public static void SetActiveButtonColour(DependencyObject target, Brush value) => target.SetValue(ActiveButtonColourProperty, value);
}
And I use the new control here:
<wpfSupport:NotificationToggleButton Command="{Binding PendingFilterButtonCommand}" IsChecked="{Binding PendingFilterSelected}"
Padding="0" ToolTip="{extensions:Translate ToolTipNotificationPendingDocumentRequest}"
Opacity="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled,
Converter={StaticResource EnabledToOpacityConverter}}" ActiveButtonColour="#4CAF50"
Template="{StaticResource NotificationToggleButtonTemplate}"/>
But the background is never set when that trigger matches. This is an update to code that works fine but which uses multiple control templates (so I'm trying to reduce code duplication). If I change the trigger Background setter to a hard coded colour it works as expected. I also don't get binding errors. So it seems as if the dependency property isn't returning the correct value.