Pergunta

When I create a custom WPF control, I usually retain the usual default appearance and effects. For example, this includes the default blue hover over a button.

I have created a custom TabControl with scrollable tabs. For whatever reason, the RepeatButton on each side (i.e. the left and right scroll arrows) have no hover effect. I have found several tutorials that tell me how to create my own hover effect for controls, but unfortunately these examples just replace the background with a different color (and this looks very different than having an animation which fades in transparent blue while keeping the underlying background). How can I get this hover effect? Is there some way that I can access the standard hover effect (might it be a storyboard?)?

Edit: I have just discovered that if I remove the custom Style that I put on the RepeatButton, I get the default hover effect. Perhaps the question is then -- How did I destroy the hover effect, and how do I mildly modify appearance without destroying it? Below is the Style which borked the hover effect-

                        <Style x:Key="TabScrollerRepeatButtonStyle" TargetType="{x:Type RepeatButton}">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Border x:Name="testTest" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Margin="1,0" CornerRadius="2">
                                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Content="{TemplateBinding ContentControl.Content}"/>
                                    </Border>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
Foi útil?

Solução

The best way to attack problems like these is to fire up Expression Blend and do 'Edit Template' for the control you want to copy styles from. Doing this for the scrollbar will show you exactly what the default style does and you can then copy relevant bits to your custom control style.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top