views:

98

answers:

1

I want to restyle just part of a WPF control.

(Specifically, I want to make the scroll buttons on a ScrollBar bigger)

Now I can do this no problem. I extracted the default style. Made the required tweaks and included the modified style in my application.

The problem is that I have to include the entire control template in the replacement style, when all I am changing is 2 values.

  <Setter Property="Control.Template">
    <Setter.Value>
      <ControlTemplate TargetType="ScrollBar">
        <Grid Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">
          <Grid.ColumnDefinitions>
            <ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}" />
            <ColumnDefinition Width="1E-05*" />
            <ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}" />
          </... etc

I just want to change the MaxWidth on the column definitions to 50.

So my question is this: Is there any way I can make this tweak to the template without having to include everything else? I still want all other parts of the control template to just work like the default.

+4  A: 

In this case you should be able to, since the template reaches out and grabs the value from a resource:

<ScrollBar xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <ScrollBar.Resources>
        <sys:Double x:Key="{x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}">50</sys:Double>
    </ScrollBar.Resources>
</ScrollBar>

If the template had hard-coded the value, you'd be out of luck.

HTH, Kent

Kent Boogaart
Fantastic. Nice one Kent.
Simon P Stevens
Cool tip, it could probably prove useful for me too :)
Thomas Levesque