wpfwpf-4.0

WPF Flat Repeat Button (ToolBar look)


I'm trying to give the RepeatButton the flat look w/o overriding the ControlTemplate. With the regular Button you can do the following (but not with the RepeatButton):

<Button BorderThickness="0" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">...

Is there something similar for the RepeatButton or for ButtonBase? I'm assuming no because if you put a RepeatButton in a ToolBar is does not get a flat look.

Is there a better way to give the RepeatButton a flat look other than overriding the ControlTemplate?


Solution

  • Here's what came up with for a flat RepeatButton Style with a Path as content:

    <Style x:Key="RepeatButtonFlat" TargetType="{x:Type RepeatButton}">
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="IsTabStop" Value="false"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RepeatButton}">
                    <Border Background="Transparent" Height="14" Width="14">
                        <Path HorizontalAlignment="Center" VerticalAlignment="Center" Stretch="Uniform" Margin="2"
                              Data="{Binding Path=Content, RelativeSource={RelativeSource TemplatedParent}}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    Sample usage:

    <RepeatButton Style="{StaticResource ScrollBarLineButton}" Content="M0,0 L1,0 .5,-.5 Z"/>