Omar Mir
Omar Mir

Reputation: 1624

ControlTemplate for ScrollBar apply only to DataGrid

Hello I have a ScrollBar Template as per below - only relevant portion shown:

<ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition MaxHeight="18"/>
            <RowDefinition Height="0.00001*"/>
            <RowDefinition MaxHeight="18"/>
        </Grid.RowDefinitions>
        <Rectangle Height="35" Width="19" Fill="{StaticResource GreenTeaBrush}" Margin="-35" VerticalAlignment="Top"/>
        <Border....

Now the Rectangle Portion:

<Rectangle Height="35" Width="19" Fill="{StaticResource GreenTeaBrush}" Margin="-35" VerticalAlignment="Top"/>

I only want that to show up on DataGrids OR i would like this enter ControlTemplate to only work on the ScrollBars of DataGrids.

Any help would be greatly appreciated! Thanks!

Upvotes: 1

Views: 978

Answers (1)

brunnerh
brunnerh

Reputation: 184524

You can nest Styles, the following style is implicitly applied to DataGrids, it contains a style for ScrollBars which is also applied implicitly:

<Style TargetType="{x:Type DataGrid}" BasedOn="{StaticResource {x:Type DataGrid}}">
    <Style.Resources>
        <Style TargetType="{x:Type ScrollBar}" BasedOn="{StaticResource {x:Type ScrollBar}}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ScrollBar}">
                        <!-- Template here -->
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Style.Resources>
</Style>

Upvotes: 3

Related Questions