Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preserve theme style of control while modifying the control template

I'm trying to add bind some commands to Slider.Thumb and this is how I currently do it:

<Style x:Key="BasicSliderStyle" TargetType="{x:Type customControls:ThumbDragSlider}" BasedOn="{StaticResource {x:Type Slider}}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Slider}">
                <Grid>
                    <Track x:Name="PART_Track">
                        <Track.Thumb>
                            <Thumb x:Name="Thumb">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="MouseEnter">
                                        <command:EventToCommand Command="{Binding PositionSliderThumbMouseEnterCommand}" PassEventArgsToCommand="True"/>
                                    </i:EventTrigger>
                                    <i:EventTrigger EventName="DragDelta">
                                        <command:EventToCommand Command="{Binding PositionThumbDragDeltaCommand}" CommandParameter="{Binding ElementName=sMovieSkipSlider}"/>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </Thumb>
                        </Track.Thumb>
                    </Track>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

The problem is that I also have a theme applied to my controls and if I use this style the style and effects from it are removed as well, is there a way to keep the current application theme style on a control while also being able to add event triggers and attach commands as show above?

P.S - Since this is a custom control that derives from Slider, this is how I set the default theme style for the slider to it

Style="{StaticResource {x:Type Slider}}"
like image 672
Deadzone Avatar asked Dec 16 '25 18:12

Deadzone


2 Answers

You can only use Triggers in the Style and not in the Template, if you want to keep the same theme for that control. That means that it is not possible in your case. What you can do is copy the entire Style of your theme and specify the trigger there.

like image 161
Marc Avatar answered Dec 19 '25 12:12

Marc


You can extend your custom style. Instead of:

BasedOn="{StaticResource {x:Type Slider}}"

do:

BasedOn="{StaticResource MyCustomSlider}"
like image 34
kaqq Avatar answered Dec 19 '25 12:12

kaqq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!