ScrollBar 的 ControlTemplate 仅适用于 DataGrid [英] ControlTemplate for ScrollBar apply only to DataGrid

查看:34
本文介绍了ScrollBar 的 ControlTemplate 仅适用于 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....

现在是矩形部分:

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

我只希望它显示在 DataGrids 上,或者我希望输入 ControlTemplate 只在 DataGrids 的 ScrollBars 上工作.

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!

推荐答案

您可以嵌套样式,以下样式隐式应用于 DataGrids,它包含 ScrollBars 的样式,也隐式应用:

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>

这篇关于ScrollBar 的 ControlTemplate 仅适用于 DataGrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆