0

I am trying to create a style for a RibbonTabHeader where when I change the SketchActive property the style changes as well. The style is defined as follows:

<Style TargetType="{x:Type RibbonTabHeader}" x:Key="RibbonSketchTabHeader" BasedOn="{StaticResource {x:Type RibbonTabHeader}}">
    <Setter Property="cprop:StillActiveHelper.IsStillActive" Value="{Binding SketchActive}"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="RibbonTabHeader">
                <Border x:Name="TabHeader" BorderThickness="1,1,1,0" CornerRadius="4,4,0,0" Background="#FFDDDDDD" BorderBrush="#FF707070" Margin="1,0">
                    <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,0"/>
                </Border>
                <ControlTemplate.Triggers>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsMouseOver" Value="True" />
                            <Condition Property="cprop:StillActiveHelper.IsStillActive" Value="False" />
                        </MultiTrigger.Conditions>
                        <Setter TargetName="TabHeader" Property="BorderThickness" Value="1,1,1,0" />
                        <Setter TargetName="TabHeader" Property="Background" Value="#3D26A0DA" />
                        <Setter TargetName="TabHeader" Property="BorderBrush" Value="#FF1A5AAB" />
                    </MultiTrigger>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsRibbonTabSelected" Value="True" />
                            <Condition Property="cprop:StillActiveHelper.IsStillActive" Value="False" />
                        </MultiTrigger.Conditions>
                        <Setter TargetName="TabHeader" Property="BorderThickness" Value="1,1,1,0" />
                        <Setter TargetName="TabHeader" Property="Background" Value="WhiteSmoke" />
                        <Setter TargetName="TabHeader" Property="BorderBrush" Value="#FF1A5AAB" />
                    </MultiTrigger>
                    <Trigger Property="cprop:StillActiveHelper.IsStillActive" Value="True">
                        <Setter TargetName="TabHeader" Property="BorderThickness" Value="1.5,1.5,1.5,0" />
                        <Setter TargetName="TabHeader" Property="Background" Value="#C7E1BB" />
                        <Setter TargetName="TabHeader" Property="BorderBrush" Value="#FF65FF19" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

The SketchActive property is on the ViewModel defined like this:

public bool SketchActive
{
    get { return sketchActive; }
    set
    {  
        sketchActive = value;
        RaisePropertyChanged(nameof(SketchActive));
        
    }
}

And last the definition of the dependency property:

public static DependencyProperty IsStillActiveProperty = DependencyProperty.RegisterAttached(
        "IsStillActive", typeof(bool), typeof(StillActiveHelper));


public bool IsStillActive
{
    get { return (bool)GetValue(IsStillActiveProperty); }
    set 
    {            
        SetValue(IsStillActiveProperty, value);                 
    }
}

Then in the ViewModel I change the SketchActive property to True, but nothing happens. The RibbonTabHeader still has the "blue style", but it should have the "green style". What am I missing?

Jaime
  • 45
  • 7
  • Besides the answers to the duplicate question, please also take a look at the documentation: [Attached properties overview](https://docs.microsoft.com/en-us/dotnet/desktop/wpf/properties/attached-properties-overview?view=netdesktop-6.0), especially the section about [Custom attached properties](https://docs.microsoft.com/en-us/dotnet/desktop/wpf/properties/attached-properties-overview?view=netdesktop-6.0#custom-attached-properties). It is also unclear from the code in your question, where exactly you *set* the attached property's value. – Clemens Feb 16 '22 at 12:40

0 Answers0