WPF DataGrid ScrollBar Style

效果图如下

代码

 <DataGrid.Resources>
                            <Style TargetType="{x:Type ScrollBar}">
                                <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
                                <Setter Property="Stylus.IsFlicksEnabled" Value="false"/>
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                                <Setter Property="Width" Value="10"/>
                                <Setter Property="MinWidth" Value="10"/>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type ScrollBar}">
                                            <Grid x:Name="Bg" SnapsToDevicePixels="true" Background="#7FBFBFBF">
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="0.00001*"/>
                                                </Grid.RowDefinitions>
                                                <Track HorizontalAlignment="Center" Name="PART_Track" Width="{TemplateBinding Width}" Maximum="{TemplateBinding Maximum}" Minimum="{TemplateBinding Minimum}"
                                    Value="{TemplateBinding Value}"  IsDirectionReversed="true">
                                                    <Track.DecreaseRepeatButton>
                                                        <RepeatButton Template="{StaticResource scroll_background}" Command="ScrollBar.LineUpCommand"  />
                                                    </Track.DecreaseRepeatButton>
                                                    <Track.IncreaseRepeatButton>
                                                        <RepeatButton Template="{StaticResource scroll_background}" Command="ScrollBar.LineDownCommand" />
                                                    </Track.IncreaseRepeatButton>
                                                    <Track.Thumb>
                                                        <Thumb Style="{StaticResource scroll_thumb_style}" >
                                                        </Thumb>
                                                    </Track.Thumb>
                                                </Track>
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                                <Style.Triggers>
                                    <Trigger Property="Orientation" Value="Horizontal">
                                        <Setter Property="Width" Value="Auto"/>
                                        <Setter Property="MinWidth" Value="0"/>
                                        <Setter Property="Height" Value="10"/>
                                        <Setter Property="MinHeight" Value="10"/>
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type ScrollBar}">
                                                    <Grid x:Name="Bg" SnapsToDevicePixels="true" Background="#7FA7A7A7">
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition Width="0.00001*"/>
                                                        </Grid.ColumnDefinitions>
                                                        <Track x:Name="PART_Track" Grid.Column="1" IsEnabled="{TemplateBinding IsMouseOver}">
                                                            <Track.DecreaseRepeatButton>
                                                                <RepeatButton Template="{StaticResource scroll_background}" Command="ScrollBar.LineUpCommand"  />
                                                            </Track.DecreaseRepeatButton>
                                                            <Track.IncreaseRepeatButton>
                                                                <RepeatButton Template="{StaticResource scroll_background}" Command="ScrollBar.LineDownCommand" />
                                                            </Track.IncreaseRepeatButton>
                                                            <Track.Thumb>
                                                                <Thumb  Style="{DynamicResource scroll_thumb_stylecrosswise}" Height="8"/>
                                                            </Track.Thumb>
                                                        </Track>
                                                    </Grid>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                            <!--<Style TargetType="ScrollBar">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="ScrollBar">
                                            <Grid Width="15">
                                                <Border Width="13" HorizontalAlignment="Center" CornerRadius="5" Background="#33555555">
                                                </Border>
                                                <Track HorizontalAlignment="Center" Name="PART_Track" Width="{TemplateBinding Width}" Maximum="{TemplateBinding Maximum}" Minimum="{TemplateBinding Minimum}"
                                    Value="{TemplateBinding Value}"  IsDirectionReversed="true">
                                                    <Track.DecreaseRepeatButton>
                                                        <RepeatButton Template="{StaticResource scroll_background}" Command="ScrollBar.LineUpCommand"  />
                                                    </Track.DecreaseRepeatButton>
                                                    <Track.IncreaseRepeatButton>
                                                        <RepeatButton Template="{StaticResource scroll_background}" Command="ScrollBar.LineDownCommand" />
                                                    </Track.IncreaseRepeatButton>
                                                    <Track.Thumb>
                                                        <Thumb Style="{StaticResource scroll_thumb_style}" >
                                                        </Thumb>
                                                    </Track.Thumb>
                                                </Track>
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>-->
                        </DataGrid.Resources>
<ControlTemplate x:Key="scroll_background" TargetType="RepeatButton">
        <Border Background="Transparent">
        </Border>
    </ControlTemplate>

    <Style x:Key="scroll_thumb_style" TargetType="Thumb">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="IsTabStop" Value="false"/>
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Thumb">
                    <Rectangle Width="10" Fill="#7D7D7D" RadiusX="5" RadiusY="5">
                    </Rectangle>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="scroll_thumb_stylecrosswise" TargetType="Thumb">
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="IsTabStop" Value="false"/>
        <Setter Property="Focusable" Value="false"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Thumb">
                    <Rectangle  Fill="#7D7D7D" RadiusX="5" RadiusY="5">
                    </Rectangle>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

原文地址:https://www.cnblogs.com/CityOfThousandFires/p/12444936.html

时间: 2024-11-05 18:54:25

WPF DataGrid ScrollBar Style的相关文章

WPF DataGrid Custommization using Style and Template

转载:http://www.codeproject.com/Articles/586132/WPF-DataGrid-Custommization-using-Style-and-Templa WPF DataGrid Custommization using Style and Template Hiren Khirsaria, 2 May 2013 CPOL customize DataGridRowHeader, DataGridColumnHeader, DataGridCell, Da

WPF Datagrid 控制 第一行和第一列之间的空白

原文:WPF Datagrid 控制 第一行和第一列之间的空白 这个位置就是 这里 我们更改 DataGridControltemplate 模板 看树形结构 里面是一个BUtton 功能是全选 能找到了 那就直接改掉就可以 <ControlTemplate x:Key="DataGridControlTemplate1" TargetType="{x:Type DataGrid}"> <Border BorderBrush="{Temp

WPF DataGrid自定义样式

WPF DataGrid自定义样式 微软的WPF DataGrid中有很多的属性和样式,你可以调整,以寻找合适的(如果你是一名设计师).下面,找到我的小抄造型的网格.它不是100%全面,但它可以让你走得很远,有一些非常有用的技巧和陷阱. 在DataGrid中的最高水平,你可以改变的外观和感觉,通过设置一些: Property Type Values Default AlternatingRowBackground Brush Any Brush Null Background Brush Any

WPF DataGrid显格式

Guide to WPF DataGrid formatting using bindings Peter Huber SG, 25 Nov 2013 CPOL    4.83 (13 votes) 1 2 3 4 5 4.83/5 - 13 votes μ 4.83, σa 0.93 [?] Rate: Add a reason or comment to your vote: x Votes of 3 or less require a comment Using Style and Bin

WPF DataGrid 之数据绑定

1. Auto generation of columns 最简单的方法莫过于让DataGrid根据数据源中的字段自动生成列了: 根据实体类的公共属性, 能够自动生成四种类型的数据列,对应关系如下: TextBox columns for string values; CheckBox columns for boolean values; ComboBox columns for enumerable values; Hyperlink columns for Uri values; 拖个Da

WPF DataGrid分页功能实现代码 修改原作者不能实现的部分

这两天需要给Datagrid加个分页,查找了一些相关的文章,发现有一个写了一个控件比较好,地址是 http://blog.csdn.net/zdw_wym/article/details/8221894 感谢这位大神12年的帖子,但是照着做了以后,发现除了点击数字和GO按钮好使意外,神马“首页.上一页.下一页.末页”都不好使. 继续找寻相关的资料和查看大神的源码,发现有的地方写的不对,因为textblock没有click事件,而大神写了click事件,所以没有得到触发,介于这个问题,我稍作了修改

xceed wpf datagrid

<!--*********************************************************************************** Extended WPF Toolkit Copyright (C) 2007-2013 Xceed Software Inc. This program is provided to you under the terms of the Microsoft Public License (Ms-PL) as publis

WPF DataGrid常用属性记录

WPF DataGrid常用属性记录 组件常用方法: BeginEdit:使DataGrid进入编辑状态. CancelEdit:取消DataGrid的编辑状态. CollapseRowGroup:闭合DataGrid的行分组. CommitEdit:确认DataGrid的编辑完成. ExpandRowGroup:展开DataGrid的行分组. GetGroupFromItem:从具体Item中得到分组. ScrollIntoView:滚动DataGrid视图. 组件常用属性: Alternat

wpf datagrid 如何让标头 及内容居中

头就是这么居中<DataGrid> <DataGrid.ColumnHeaderStyle> <Style TargetType="DataGridColumnHeader"> <Setter Property="HorizontalContentAlignment" Value="Center"> </Setter> </Style> </DataGrid.Colum