开发者

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*"/>
  开发者_Python百科          <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!


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜