ControlTemplate for ScrollBar apply only to DataGrid

二次信任 提交于 2019-12-23 04:14:11

问题


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!


回答1:


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>


来源:https://stackoverflow.com/questions/6255174/controltemplate-for-scrollbar-apply-only-to-datagrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!