Search code examples
wpfcontroltemplatecolor-picker

Define new ControlTemplate keeping the original events


I want to use the ExtendedWPFToolkits's ColorPicker but with a custom ButtonStyle. I can create a new look overriding the Template property of the item but the original templates click event is missing.

I want to keep it, but how?

<Controls:ColorPicker >
    <Controls:ColorPicker.ButtonStyle>
        <Style TargetType="{x:Type ToggleButton}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Button Content="ColorPicker"></Button>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Controls:ColorPicker.ButtonStyle>
</Controls:ColorPicker>

Solution

  • What you have is not valid. You are putting a Button in the ControlTemplate of a ToggleButton, so basically a button in a button.

    You'd need to do something like:

    <Controls:ColorPicker >
        <Controls:ColorPicker.ButtonStyle>
            <Style TargetType="{x:Type ToggleButton}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate>
                            <Border Background="Transparent">
                                <TextBlock Text="ColorPicker" />
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Controls:ColorPicker.ButtonStyle>
    </Controls:ColorPicker>
    

    I added a transparent Border so the button will be able to receive mouse events for areas not covered by the text.