Question

I have a button template, where ContentPresenter is actually a Path.

On MouseOver, I want to change the Path.Fill.

See the template:

    <Style x:Key="spinButtonStyle" TargetType="{x:Type RepeatButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border x:Name="Bd" BorderThickness="0" Background="Transparent" CornerRadius="2">
                        <ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" TargetName="Bd" Value="#666666"/>
                            <Setter Property="Control.Foreground" Value="#999999"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

And the code that uses this template:

<RepeatButton Style="{StaticResource spinButtonStyle}">
    <Path blah blah blah/>
</RepeatButton>

Now, in this case, that ContentPresenter is a Path. Is there any way to change the Path.Fill color in the XAML?

Was it helpful?

Solution

All you need to do now is bind the Path Fill property to your RepeatButton Foreground property:

Fill="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type RepeatButton}}}"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top