欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

WPF自定义DataGrid XAML代码

程序员文章站 2022-06-08 10:49:10
...
<DataGrid x:Name="DataGrid_DSXX" Margin="8,6,8,2" Background="#00000000" RowBackground="#00001F3E" Foreground="Gainsboro" AlternatingRowBackground="#00000000" CanUserAddRows="False" CanUserDeleteRows="False" HeadersVisibility="None" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" HorizontalGridLinesBrush="#FF0382D6" VerticalGridLinesBrush="#FF0382D6" IsReadOnly="True" BorderBrush="#FF0382D6">
                    <!--<DataGrid.RowStyle >
                            <Style TargetType="DataGridRow">
                                <Style.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Background" Value="#FF3C3C3C"/>
                                        <Setter Property="BorderBrush" Value="#FF3C3C3C"/>
                                        <Setter Property="FontSize" Value=" 12"/>
                                        <Setter Property="Foreground" Value="#FFC8C8C8"/>
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </DataGrid.RowStyle>-->
                    <DataGrid.CellStyle >
                        <Style TargetType="{x:Type DataGridCell}">
                            <Style.Triggers >
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Background" Value="#FF3E3E42"/>
                                    <Setter Property="BorderBrush" Value="#FF3E3E42"/>
                                    <Setter Property="FontSize" Value="12"/>
                                    <Setter Property="Foreground" Value="#FF0581D4"/>
                                </Trigger>
                                <Trigger Property="IsSelected" Value="True">
                                    <Setter Property="Background" Value="#FF282828"/>
                                    <Setter Property="BorderBrush" Value="#FF282828"/>
                                    <Setter Property="FontSize" Value="12"/>
                                    <Setter Property="Foreground" Value="#FF0581D4"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </DataGrid.CellStyle>
                    <DataGrid.ColumnHeaderStyle>
                        <Style TargetType="{x:Type DataGridColumnHeader}">
                            <Setter Property="Height" Value="23"/>
                            <Setter Property="Background" Value="#FF444444"/>
                            <Setter Property="Foreground" Value="White"/>
                            <Setter Property="FontSize" Value="13"/>
                            <Setter Property="HorizontalContentAlignment" Value="Center"/>
                            <Setter Property="VerticalAlignment" Value="Center" />
                            <Setter Property="BorderBrush" Value="#FF0382D6"/>
                            <Setter Property="BorderThickness" Value="0.5,0,0.5,1"/>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="ToolTip" Value="Click to sort."/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </DataGrid.ColumnHeaderStyle>
                    <DataGrid.Template>
                        <ControlTemplate TargetType="{x:Type DataGrid}">
                            <Border BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="0" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="True">
                                <ScrollViewer x:Name="DG_ScrollViewer" Focusable="False">
                                    <ScrollViewer.Template>
                                        <ControlTemplate TargetType="{x:Type ScrollViewer}">
                                            <Grid Background="#FF444444">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                </Grid.ColumnDefinitions>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="*"/>
                                                    <RowDefinition Height="Auto"/>
                                                </Grid.RowDefinitions>
                                                <Button Command="ApplicationCommands.SelectAll" Focusable="False" Style="{DynamicResource {ComponentResourceKey ResourceId=DataGridSelectAllButtonStyle, TypeInTargetAssembly={x:Type DataGrid}}}" Width="{Binding CellsPanelHorizontalOffset, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}}" Background="#FF444444" BorderBrush="#FF444444" Foreground="White">
                                                    <Button.Template>
                                                        <ControlTemplate TargetType="{x:Type Button}">
                                                            <Grid Background="#FF444444">
                                                                <Rectangle x:Name="Border" Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" SnapsToDevicePixels="True"/>
                                                                <Polygon x:Name="Arrow" Fill="#FF444444" HorizontalAlignment="Right" Margin="8,8,3,3" Opacity="0.15" Points="0,10 10,10 10,0" Stretch="Uniform" VerticalAlignment="Bottom"/>
                                                            </Grid>
                                                            <ControlTemplate.Triggers>
                                                                <Trigger Property="IsMouseOver" Value="True">
                                                                    <Setter Property="Stroke" TargetName="Border" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/>
                                                                </Trigger>
                                                                <Trigger Property="IsPressed" Value="True">
                                                                    <Setter Property="Fill" TargetName="Border" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/>
                                                                </Trigger>
                                                                <Trigger Property="IsEnabled" Value="False">
                                                                    <Setter Property="Visibility" TargetName="Arrow" Value="Collapsed"/>
                                                                </Trigger>
                                                            </ControlTemplate.Triggers>
                                                        </ControlTemplate>
                                                    </Button.Template>
                                                    <Button.Visibility>
                                                        <Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
                                                            <Binding.ConverterParameter>
                                                                <DataGridHeadersVisibility>All</DataGridHeadersVisibility>
                                                            </Binding.ConverterParameter>
                                                        </Binding>
                                                    </Button.Visibility>
                                                </Button>
                                                <DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Grid.Column="1" Background="#FF444444" BorderBrush="#FF0382D6" BorderThickness="1" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
                                                    <DataGridColumnHeadersPresenter.Template>
                                                        <ControlTemplate TargetType="{x:Type DataGridColumnHeadersPresenter}">
                                                            <Grid Background="#FF444444">
                                                                <DataGridColumnHeader x:Name="PART_FillerColumnHeader" IsHitTestVisible="False" Background="#FF444444" BorderBrush="#FF0382D6" Foreground="White" HorizontalContentAlignment="Center">
                                                                    <DataGridColumnHeader.Template>
                                                                        <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                                                                            <Grid Background="#FF444444">
                                                                                <Themes:DataGridHeaderBorder BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" IsClickable="{TemplateBinding CanUserSort}" IsPressed="{TemplateBinding IsPressed}" IsHovered="{TemplateBinding IsMouseOver}" Padding="{TemplateBinding Padding}" SortDirection="{TemplateBinding SortDirection}" SeparatorBrush="{TemplateBinding SeparatorBrush}" SeparatorVisibility="{TemplateBinding SeparatorVisibility}">
                                                                                    <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                                                                </Themes:DataGridHeaderBorder>
                                                                                <Thumb x:Name="PART_LeftHeaderGripper" HorizontalAlignment="Left" Background="#FF444444" BorderBrush="#FF444444" Foreground="White" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
                                                                                    <Thumb.Style>
                                                                                        <Style TargetType="{x:Type Thumb}">
                                                                                            <Setter Property="Width" Value="8"/>
                                                                                            <Setter Property="Background" Value="Transparent"/>
                                                                                            <Setter Property="Cursor" Value="SizeWE"/>
                                                                                            <Setter Property="Template">
                                                                                                <Setter.Value>
                                                                                                    <ControlTemplate TargetType="{x:Type Thumb}">
                                                                                                        <Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
                                                                                                    </ControlTemplate>
                                                                                                </Setter.Value>
                                                                                            </Setter>
                                                                                        </Style>
                                                                                    </Thumb.Style>
                                                                                </Thumb>
                                                                                <Thumb x:Name="PART_RightHeaderGripper" HorizontalAlignment="Right" Background="#FF444444" BorderBrush="#FF444444" Foreground="White">
                                                                                    <Thumb.Style>
                                                                                        <Style TargetType="{x:Type Thumb}">
                                                                                            <Setter Property="Width" Value="8"/>
                                                                                            <Setter Property="Background" Value="Transparent"/>
                                                                                            <Setter Property="Cursor" Value="SizeWE"/>
                                                                                            <Setter Property="Template">
                                                                                                <Setter.Value>
                                                                                                    <ControlTemplate TargetType="{x:Type Thumb}">
                                                                                                        <Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
                                                                                                    </ControlTemplate>
                                                                                                </Setter.Value>
                                                                                            </Setter>
                                                                                        </Style>
                                                                                    </Thumb.Style>
                                                                                </Thumb>
                                                                            </Grid>
                                                                        </ControlTemplate>
                                                                    </DataGridColumnHeader.Template>
                                                                </DataGridColumnHeader>
                                                                <ItemsPresenter/>
                                                            </Grid>
                                                        </ControlTemplate>
                                                    </DataGridColumnHeadersPresenter.Template>
                                                    <DataGridColumnHeadersPresenter.Visibility>
                                                        <Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}">
                                                            <Binding.ConverterParameter>
                                                                <DataGridHeadersVisibility>Column</DataGridHeadersVisibility>
                                                            </Binding.ConverterParameter>
                                                        </Binding>
                                                    </DataGridColumnHeadersPresenter.Visibility>
                                                </DataGridColumnHeadersPresenter>
                                                <ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" CanHorizontallyScroll="False" Grid.ColumnSpan="2" CanVerticallyScroll="False" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Grid.Row="1"/>
                                                <ScrollBar x:Name="PART_VerticalScrollBar" Grid.Column="2" Maximum="{TemplateBinding ScrollableHeight}" Orientation="Vertical" Grid.Row="1" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}" Background="#FF444444" BorderBrush="#FF444444">
                                                    <ScrollBar.Template>
                                                        <ControlTemplate TargetType="{x:Type ScrollBar}">
                                                            <Grid x:Name="Bg" SnapsToDevicePixels="True">
                                                                <Grid.RowDefinitions>
                                                                    <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"/>
                                                                    <RowDefinition Height="1E-05*"/>
                                                                    <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}"/>
                                                                </Grid.RowDefinitions>
                                                                <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Row="1"/>
                                                                <RepeatButton x:Name="PART_LineUpButton" Command="ScrollBar.LineUpCommand" IsEnabled="{TemplateBinding IsMouseOver}">
                                                                    <RepeatButton.Style>
                                                                        <Style TargetType="{x:Type RepeatButton}">
                                                                            <Setter Property="FocusVisualStyle">
                                                                                <Setter.Value>
                                                                                    <Style>
                                                                                        <Setter Property="Control.Template">
                                                                                            <Setter.Value>
                                                                                                <ControlTemplate>
                                                                                                    <Rectangle Margin="2" SnapsToDevicePixels="True" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
                                                                                                </ControlTemplate>
                                                                                            </Setter.Value>
                                                                                        </Setter>
                                                                                    </Style>
                                                                                </Setter.Value>
                                                                            </Setter>
                                                                            <Setter Property="BorderThickness" Value="1"/>
                                                                            <Setter Property="HorizontalContentAlignment" Value="Center"/>
                                                                            <Setter Property="VerticalContentAlignment" Value="Center"/>
                                                                            <Setter Property="Padding" Value="1"/>
                                                                            <Setter Property="Focusable" Value="False"/>
                                                                            <Setter Property="IsTabStop" Value="False"/>
                                                                            <Setter Property="Template">
                                                                                <Setter.Value>
                                                                                    <ControlTemplate TargetType="{x:Type RepeatButton}">
                                                                                        <Border x:Name="border" BorderBrush="#FF444444" BorderThickness="1" Background="#FF444444" SnapsToDevicePixels="True">
                                                                                            <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                                                                        </Border>
                                                                                        <ControlTemplate.Triggers>
                                                                                            <Trigger Property="IsMouseOver" Value="True">
                                                                                                <Setter Property="Background" TargetName="border" Value="#FF444444"/>
                                                                                                <Setter Property="BorderBrush" TargetName="border" Value="#FF444444"/>
                                                                                            </Trigger>
                                                                                            <Trigger Property="IsPressed" Value="True">
                                                                                                <Setter Property="Background" TargetName="border" Value="#FF444444"/>
                                                                                                <Setter Property="BorderBrush" TargetName="border" Value="#FF444444"/>
                                                                                            </Trigger>
                                                                                            <Trigger Property="IsEnabled" Value="False">
                                                                                                <Setter Property="Opacity" TargetName="contentPresenter" Value="0.56"/>
                                                                                                <Setter Property="Background" TargetName="border" Value="#FF444444"/>
                                                                                                <Setter Property="BorderBrush" TargetName="border" Value="#FF444444"/>
                                                                                            </Trigger>
                                                                                        </ControlTemplate.Triggers>
                                                                                    </ControlTemplate>
                                                                                </Setter.Value>
                                                                            </Setter>
                                                                        </Style>
                                                                    </RepeatButton.Style>
                                                                    <Path x:Name="ArrowTop" Data="M0,4C0,4 0,6 0,6 0,6 3.5,2.5 3.5,2.5 3.5,2.5 7,6 7,6 7,6 7,4 7,4 7,4 3.5,0.5 3.5,0.5 3.5,0.5 0,4 0,4z" Fill="#FF606060" Margin="3,4,3,3" Stretch="Uniform"/>
                                                                </RepeatButton>
                                                                <Track x:Name="PART_Track" IsDirectionReversed="True" IsEnabled="{TemplateBinding IsMouseOver}" Grid.Row="1">
                                                                    <Track.DecreaseRepeatButton>
                                                                        <RepeatButton Command="ScrollBar.PageUpCommand">
                                                                            <RepeatButton.Style>
                                                                                <Style TargetType="{x:Type RepeatButton}">
                                                                                    <Setter Property="OverridesDefaultStyle" Value="True"/>
                                                                                    <Setter Property="Background" Value="#FF444444"/>
                                                                                    <Setter Property="Focusable" Value="False"/>
                                                                                    <Setter Property="IsTabStop" Value="False"/>
                                                                                    <Setter Property="Template">
                                                                                        <Setter.Value>
                                                                                            <ControlTemplate TargetType="{x:Type RepeatButton}">
                                                                                                <Rectangle Fill="{TemplateBinding Background}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"/>
                                                                                            </ControlTemplate>
                                                                                        </Setter.Value>
                                                                                    </Setter>
                                                                                </Style>
                                                                            </RepeatButton.Style>
                                                                        </RepeatButton>
                                                                    </Track.DecreaseRepeatButton>
                                                                    <Track.IncreaseRepeatButton>
                                                                        <RepeatButton Command="ScrollBar.PageDownCommand">
                                                                            <RepeatButton.Style>
                                                                                <Style TargetType="{x:Type RepeatButton}">
                                                                                    <Setter Property="OverridesDefaultStyle" Value="True"/>
                                                                                    <Setter Property="Background" Value="#FF444444"/>
                                                                                    <Setter Property="Focusable" Value="False"/>
                                                                                    <Setter Property="IsTabStop" Value="False"/>
                                                                                    <Setter Property="Template">
                                                                                        <Setter.Value>
                                                                                            <ControlTemplate TargetType="{x:Type RepeatButton}">
                                                                                                <Rectangle Fill="{TemplateBinding Background}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"/>
                                                                                            </ControlTemplate>
                                                                                        </Setter.Value>
                                                                                    </Setter>
                                                                                </Style>
                                                                            </RepeatButton.Style>
                                                                        </RepeatButton>
                                                                    </Track.IncreaseRepeatButton>
                                                                    <Track.Thumb>
                                                                        <Thumb>
                                                                            <Thumb.Style>
                                                                                <Style TargetType="{x:Type Thumb}">
                                                                                    <Setter Property="OverridesDefaultStyle" Value="True"/>
                                                                                    <Setter Property="IsTabStop" Value="False"/>
                                                                                    <Setter Property="Template">
                                                                                        <Setter.Value>
                                                                                            <ControlTemplate TargetType="{x:Type Thumb}">
                                                                                                <Rectangle x:Name="rectangle" Fill="#FF3B3B3B" Height="{TemplateBinding Height}" SnapsToDevicePixels="True" Width="{TemplateBinding Width}"/>
                                                                                                <ControlTemplate.Triggers>
                                                                                                    <Trigger Property="IsMouseOver" Value="True">
                                                                                                        <Setter Property="Fill" TargetName="rectangle" Value="#FF373737"/>
                                                                                                    </Trigger>
                                                                                                    <Trigger Property="IsDragging" Value="True">
                                                                                                        <Setter Property="Fill" TargetName="rectangle" Value="#FF373737"/>
                                                                                                    </Trigger>
                                                                                                </ControlTemplate.Triggers>
                                                                                            </ControlTemplate>
                                                                                        </Setter.Value>
                                                                                    </Setter>
                                                                                </Style>
                                                                            </Thumb.Style>
                                                                        </Thumb>
                                                                    </Track.Thumb>
                                                                </Track>
                                                                <RepeatButton x:Name="PART_LineDownButton" Command="ScrollBar.LineDownCommand" IsEnabled="{TemplateBinding IsMouseOver}" Grid.Row="2">
                                                                    <RepeatButton.Style>
                                                                        <Style TargetType="{x:Type RepeatButton}">
                                                                            <Setter Property="FocusVisualStyle">
                                                                                <Setter.Value>
                                                                                    <Style>
                                                                                        <Setter Property="Control.Template">
                                                                                            <Setter.Value>
                                                                                                <ControlTemplate>
                                                                                                    <Rectangle Margin="2" SnapsToDevicePixels="True" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
                                                                                                </ControlTemplate>
                                                                                            </Setter.Value>
                                                                                        </Setter>
                                                                                    </Style>
                                                                                </Setter.Value>
                                                                            </Setter>
                                                                            <Setter Property="BorderThickness" Value="1"/>
                                                                            <Setter Property="HorizontalContentAlignment" Value="Center"/>
                                                                            <Setter Property="VerticalContentAlignment" Value="Center"/>
                                                                            <Setter Property="Padding" Value="1"/>
                                                                            <Setter Property="Focusable" Value="False"/>
                                                                            <Setter Property="IsTabStop" Value="False"/>
                                                                            <Setter Property="Template">
                                                                                <Setter.Value>
                                                                                    <ControlTemplate TargetType="{x:Type RepeatButton}">
                                                                                        <Border x:Name="border" BorderBrush="#FF444444" BorderThickness="1" Background="#FF444444" SnapsToDevicePixels="True">
                                                                                            <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                                                                        </Border>
                                                                                        <ControlTemplate.Triggers>
                                                                                            <Trigger Property="IsMouseOver" Value="True">
                                                                                                <Setter Property="Background" TargetName="border" Value="#FF444444"/>
                                                                                                <Setter Property="BorderBrush" TargetName="border" Value="#FF444444"/>
                                                                                            </Trigger>
                                                                                            <Trigger Property="IsPressed" Value="True">
                                                                                                <Setter Property="Background" TargetName="border" Value="#FF444444"/>
                                                                                                <Setter Property="BorderBrush" TargetName="border" Value="#FF444444"/>
                                                                                            </Trigger>
                                                                                            <Trigger Property="IsEnabled" Value="False">
                                                                                                <Setter Property="Opacity" TargetName="contentPresenter" Value="0.56"/>
                                                                                                <Setter Property="Background" TargetName="border" Value="#FF444444"/>
                                                                                                <Setter Property="BorderBrush" TargetName="border" Value="#FF444444"/>
                                                                                            </Trigger>
                                                                                        </ControlTemplate.Triggers>
                                                                                    </ControlTemplate>
                                                                                </Setter.Value>
                                                                            </Setter>
                                                                        </Style>
                                                                    </RepeatButton.Style>
                                                                    <Path x:Name="ArrowBottom" Data="M0,2.5C0,2.5 0,0.5 0,0.5 0,0.5 3.5,4 3.5,4 3.5,4 7,0.5 7,0.5 7,0.5 7,2.5 7,2.5 7,2.5 3.5,6 3.5,6 3.5,6 0,2.5 0,2.5z" Fill="#FF606060" Margin="3,4,3,3" Stretch="Uniform"/>
                                                                </RepeatButton>
                                                            </Grid>
                                                            <ControlTemplate.Triggers>
                                                                <MultiDataTrigger>
                                                                    <MultiDataTrigger.Conditions>
                                                                        <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineDownButton}" Value="true"/>
                                                                        <Condition Binding="{Binding IsPressed, ElementName=PART_LineDownButton}" Value="true"/>
                                                                    </MultiDataTrigger.Conditions>
                                                                    <Setter Property="Fill" TargetName="ArrowBottom" Value="Gray"/>
                                                                </MultiDataTrigger>
                                                                <MultiDataTrigger>
                                                                    <MultiDataTrigger.Conditions>
                                                                        <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineUpButton}" Value="true"/>
                                                                        <Condition Binding="{Binding IsPressed, ElementName=PART_LineUpButton}" Value="true"/>
                                                                    </MultiDataTrigger.Conditions>
                                                                    <Setter Property="Fill" TargetName="ArrowTop" Value="Gray"/>
                                                                </MultiDataTrigger>
                                                                <MultiDataTrigger>
                                                                    <MultiDataTrigger.Conditions>
                                                                        <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineDownButton}" Value="true"/>
                                                                        <Condition Binding="{Binding IsPressed, ElementName=PART_LineDownButton}" Value="false"/>
                                                                    </MultiDataTrigger.Conditions>
                                                                    <Setter Property="Fill" TargetName="ArrowBottom" Value="Gray"/>
                                                                </MultiDataTrigger>
                                                                <MultiDataTrigger>
                                                                    <MultiDataTrigger.Conditions>
                                                                        <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineUpButton}" Value="true"/>
                                                                        <Condition Binding="{Binding IsPressed, ElementName=PART_LineUpButton}" Value="false"/>
                                                                    </MultiDataTrigger.Conditions>
                                                                    <Setter Property="Fill" TargetName="ArrowTop" Value="Gray"/>
                                                                </MultiDataTrigger>
                                                                <Trigger Property="IsEnabled" Value="False">
                                                                    <Setter Property="Fill" TargetName="ArrowTop" Value="#FF444444"/>
                                                                    <Setter Property="Fill" TargetName="ArrowBottom" Value="#FF444444"/>
                                                                </Trigger>
                                                            </ControlTemplate.Triggers>
                                                        </ControlTemplate>
                                                    </ScrollBar.Template>
                                                </ScrollBar>
                                                <Grid Grid.Column="1" Grid.Row="2">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="{Binding NonFrozenColumnsViewportHorizontalOffset, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type DataGrid}}}"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                    <ScrollBar x:Name="PART_HorizontalScrollBar" Grid.Column="1" Maximum="{TemplateBinding ScrollableWidth}" Orientation="Horizontal" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}" Background="#FF444444" BorderBrush="#00000000">
                                                        <ScrollBar.Template>
                                                            <ControlTemplate TargetType="{x:Type ScrollBar}">
                                                                <Grid x:Name="Bg" SnapsToDevicePixels="True" Background="#FF444444">
                                                                    <Grid.ColumnDefinitions>
                                                                        <ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}"/>
                                                                        <ColumnDefinition Width="1E-05*"/>
                                                                        <ColumnDefinition MaxWidth="{DynamicResource {x:Static SystemParameters.HorizontalScrollBarButtonWidthKey}}"/>
                                                                    </Grid.ColumnDefinitions>
                                                                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="1"/>
                                                                    <RepeatButton x:Name="PART_LineLeftButton" Command="ScrollBar.LineLeftCommand" IsEnabled="{TemplateBinding IsMouseOver}" Background="#FF444444" BorderBrush="#FF444444">
                                                                        <RepeatButton.Style>
                                                                            <Style TargetType="{x:Type RepeatButton}">
                                                                                <Setter Property="FocusVisualStyle">
                                                                                    <Setter.Value>
                                                                                        <Style>
                                                                                            <Setter Property="Control.Template">
                                                                                                <Setter.Value>
                                                                                                    <ControlTemplate>
                                                                                                        <Rectangle Margin="2" SnapsToDevicePixels="True" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
                                                                                                    </ControlTemplate>
                                                                                                </Setter.Value>
                                                                                            </Setter>
                                                                                        </Style>
                                                                                    </Setter.Value>
                                                                                </Setter>
                                                                                <Setter Property="BorderThickness" Value="1"/>
                                                                                <Setter Property="HorizontalContentAlignment" Value="Center"/>
                                                                                <Setter Property="VerticalContentAlignment" Value="Center"/>
                                                                                <Setter Property="Padding" Value="1"/>
                                                                                <Setter Property="Focusable" Value="False"/>
                                                                                <Setter Property="IsTabStop" Value="False"/>
                                                                                <Setter Property="Template">
                                                                                    <Setter.Value>
                                                                                        <ControlTemplate TargetType="{x:Type RepeatButton}">
                                                                                            <Border x:Name="border" BorderBrush="#FF444444" BorderThickness="1" Background="#FF444444" SnapsToDevicePixels="True">
                                                                                                <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                                                                            </Border>
                                                                                            <ControlTemplate.Triggers>
                                                                                                <Trigger Property="IsMouseOver" Value="True">
                                                                                                    <Setter Property="Background" TargetName="border" Value="#FF444444"/>
                                                                                                    <Setter Property="BorderBrush" TargetName="border" Value="#FF444444"/>
                                                                                                </Trigger>
                                                                                                <Trigger Property="IsPressed" Value="True">
                                                                                                    <Setter Property="Background" TargetName="border" Value="#FF444444"/>
                                                                                                    <Setter Property="BorderBrush" TargetName="border" Value="#FF444444"/>
                                                                                                </Trigger>
                                                                                                <Trigger Property="IsEnabled" Value="False">
                                                                                                    <Setter Property="Opacity" TargetName="contentPresenter" Value="0.56"/>
                                                                                                    <Setter Property="Background" TargetName="border" Value="#FF444444"/>
                                                                                                    <Setter Property="BorderBrush" TargetName="border" Value="#FF444444"/>
                                                                                                </Trigger>
                                                                                            </ControlTemplate.Triggers>
                                                                                        </ControlTemplate>
                                                                                    </Setter.Value>
                                                                                </Setter>
                                                                            </Style>
                                                                        </RepeatButton.Style>
                                                                        <Path x:Name="ArrowLeft" Data="M3.18,7C3.18,7 5,7 5,7 5,7 1.81,3.5 1.81,3.5 1.81,3.5 5,0 5,0 5,0 3.18,0 3.18,0 3.18,0 0,3.5 0,3.5 0,3.5 3.18,7 3.18,7z" Fill="#FF606060" Margin="3" Stretch="Uniform"/>
                                                                    </RepeatButton>
                                                                    <Track x:Name="PART_Track" Grid.Column="1" IsEnabled="{TemplateBinding IsMouseOver}">
                                                                        <Track.DecreaseRepeatButton>
                                                                            <RepeatButton Command="ScrollBar.PageLeftCommand">
                                                                                <RepeatButton.Style>
                                                                                    <Style TargetType="{x:Type RepeatButton}">
                                                                                        <Setter Property="OverridesDefaultStyle" Value="True"/>
                                                                                        <Setter Property="Background" Value="#FF444444"/>
                                                                                        <Setter Property="Focusable" Value="False"/>
                                                                                        <Setter Property="IsTabStop" Value="False"/>
                                                                                        <Setter Property="Template">
                                                                                            <Setter.Value>
                                                                                                <ControlTemplate TargetType="{x:Type RepeatButton}">
                                                                                                    <Rectangle Fill="{TemplateBinding Background}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"/>
                                                                                                </ControlTemplate>
                                                                                            </Setter.Value>
                                                                                        </Setter>
                                                                                    </Style>
                                                                                </RepeatButton.Style>
                                                                            </RepeatButton>
                                                                        </Track.DecreaseRepeatButton>
                                                                        <Track.IncreaseRepeatButton>
                                                                            <RepeatButton Command="ScrollBar.PageRightCommand">
                                                                                <RepeatButton.Style>
                                                                                    <Style TargetType="{x:Type RepeatButton}">
                                                                                        <Setter Property="OverridesDefaultStyle" Value="True"/>
                                                                                        <Setter Property="Background" Value="#FF444444"/>
                                                                                        <Setter Property="Focusable" Value="False"/>
                                                                                        <Setter Property="IsTabStop" Value="False"/>
                                                                                        <Setter Property="Template">
                                                                                            <Setter.Value>
                                                                                                <ControlTemplate TargetType="{x:Type RepeatButton}">
                                                                                                    <Rectangle Fill="{TemplateBinding Background}" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}"/>
                                                                                                </ControlTemplate>
                                                                                            </Setter.Value>
                                                                                        </Setter>
                                                                                    </Style>
                                                                                </RepeatButton.Style>
                                                                            </RepeatButton>
                                                                        </Track.IncreaseRepeatButton>
                                                                        <Track.Thumb>
                                                                            <Thumb Background="#FF444444">
                                                                                <Thumb.Style>
                                                                                    <Style TargetType="{x:Type Thumb}">
                                                                                        <Setter Property="OverridesDefaultStyle" Value="True"/>
                                                                                        <Setter Property="IsTabStop" Value="False"/>
                                                                                        <Setter Property="Template">
                                                                                            <Setter.Value>
                                                                                                <ControlTemplate TargetType="{x:Type Thumb}">
                                                                                                    <Rectangle x:Name="rectangle" Fill="#FF3B3B3B" Height="{TemplateBinding Height}" SnapsToDevicePixels="True" Width="{TemplateBinding Width}"/>
                                                                                                    <ControlTemplate.Triggers>
                                                                                                        <Trigger Property="IsMouseOver" Value="True">
                                                                                                            <Setter Property="Fill" TargetName="rectangle" Value="#FF373737"/>
                                                                                                        </Trigger>
                                                                                                        <Trigger Property="IsDragging" Value="True">
                                                                                                            <Setter Property="Fill" TargetName="rectangle" Value="#FF373737"/>
                                                                                                        </Trigger>
                                                                                                    </ControlTemplate.Triggers>
                                                                                                </ControlTemplate>
                                                                                            </Setter.Value>
                                                                                        </Setter>
                                                                                    </Style>
                                                                                </Thumb.Style>
                                                                            </Thumb>
                                                                        </Track.Thumb>
                                                                    </Track>
                                                                    <RepeatButton x:Name="PART_LineRightButton" Grid.Column="2" Command="ScrollBar.LineRightCommand" IsEnabled="{TemplateBinding IsMouseOver}" Background="#FF444444" BorderBrush="#FF444444">
                                                                        <RepeatButton.Style>
                                                                            <Style TargetType="{x:Type RepeatButton}">
                                                                                <Setter Property="FocusVisualStyle">
                                                                                    <Setter.Value>
                                                                                        <Style>
                                                                                            <Setter Property="Control.Template">
                                                                                                <Setter.Value>
                                                                                                    <ControlTemplate>
                                                                                                        <Rectangle Margin="2" SnapsToDevicePixels="True" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2" Fill="#FF444444"/>
                                                                                                    </ControlTemplate>
                                                                                                </Setter.Value>
                                                                                            </Setter>
                                                                                        </Style>
                                                                                    </Setter.Value>
                                                                                </Setter>
                                                                                <Setter Property="BorderThickness" Value="1"/>
                                                                                <Setter Property="HorizontalContentAlignment" Value="Center"/>
                                                                                <Setter Property="VerticalContentAlignment" Value="Center"/>
                                                                                <Setter Property="Padding" Value="1"/>
                                                                                <Setter Property="Focusable" Value="False"/>
                                                                                <Setter Property="IsTabStop" Value="False"/>
                                                                                <Setter Property="Template">
                                                                                    <Setter.Value>
                                                                                        <ControlTemplate TargetType="{x:Type RepeatButton}">
                                                                                            <Border x:Name="border" BorderBrush="#FF444444" BorderThickness="1" Background="#FF444444" SnapsToDevicePixels="True">
                                                                                                <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                                                                            </Border>
                                                                                            <ControlTemplate.Triggers>
                                                                                                <Trigger Property="IsMouseOver" Value="True">
                                                                                                    <Setter Property="Background" TargetName="border" Value="#FF444444"/>
                                                                                                    <Setter Property="BorderBrush" TargetName="border" Value="#FF444444"/>
                                                                                                </Trigger>
                                                                                                <Trigger Property="IsPressed" Value="True">
                                                                                                    <Setter Property="Background" TargetName="border" Value="#FF444444"/>
                                                                                                    <Setter Property="BorderBrush" TargetName="border" Value="#FF444444"/>
                                                                                                </Trigger>
                                                                                                <Trigger Property="IsEnabled" Value="False">
                                                                                                    <Setter Property="Opacity" TargetName="contentPresenter" Value="0.56"/>
                                                                                                    <Setter Property="Background" TargetName="border" Value="#FF444444"/>
                                                                                                    <Setter Property="BorderBrush" TargetName="border" Value="#FF444444"/>
                                                                                                </Trigger>
                                                                                            </ControlTemplate.Triggers>
                                                                                        </ControlTemplate>
                                                                                    </Setter.Value>
                                                                                </Setter>
                                                                            </Style>
                                                                        </RepeatButton.Style>
                                                                        <Path x:Name="ArrowRight" Data="M1.81,7C1.81,7 0,7 0,7 0,7 3.18,3.5 3.18,3.5 3.18,3.5 0,0 0,0 0,0 1.81,0 1.81,0 1.81,0 5,3.5 5,3.5 5,3.5 1.81,7 1.81,7z" Fill="#FF606060" Margin="3" Stretch="Uniform"/>
                                                                    </RepeatButton>
                                                                </Grid>
                                                                <ControlTemplate.Triggers>
                                                                    <MultiDataTrigger>
                                                                        <MultiDataTrigger.Conditions>
                                                                            <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineRightButton}" Value="true"/>
                                                                            <Condition Binding="{Binding IsPressed, ElementName=PART_LineRightButton}" Value="true"/>
                                                                        </MultiDataTrigger.Conditions>
                                                                        <Setter Property="Fill" TargetName="ArrowRight" Value="Gray"/>
                                                                    </MultiDataTrigger>
                                                                    <MultiDataTrigger>
                                                                        <MultiDataTrigger.Conditions>
                                                                            <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineLeftButton}" Value="true"/>
                                                                            <Condition Binding="{Binding IsPressed, ElementName=PART_LineLeftButton}" Value="true"/>
                                                                        </MultiDataTrigger.Conditions>
                                                                        <Setter Property="Fill" TargetName="ArrowLeft" Value="Gray"/>
                                                                    </MultiDataTrigger>
                                                                    <MultiDataTrigger>
                                                                        <MultiDataTrigger.Conditions>
                                                                            <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineRightButton}" Value="true"/>
                                                                            <Condition Binding="{Binding IsPressed, ElementName=PART_LineRightButton}" Value="false"/>
                                                                        </MultiDataTrigger.Conditions>
                                                                        <Setter Property="Fill" TargetName="ArrowRight" Value="Gray"/>
                                                                    </MultiDataTrigger>
                                                                    <MultiDataTrigger>
                                                                        <MultiDataTrigger.Conditions>
                                                                            <Condition Binding="{Binding IsMouseOver, ElementName=PART_LineLeftButton}" Value="true"/>
                                                                            <Condition Binding="{Binding IsPressed, ElementName=PART_LineLeftButton}" Value="false"/>
                                                                        </MultiDataTrigger.Conditions>
                                                                        <Setter Property="Fill" TargetName="ArrowLeft" Value="Gray"/>
                                                                    </MultiDataTrigger>
                                                                    <Trigger Property="IsEnabled" Value="False">
                                                                        <Setter Property="Fill" TargetName="ArrowLeft" Value="Gray"/>
                                                                        <Setter Property="Fill" TargetName="ArrowRight" Value="Gray"/>
                                                                    </Trigger>
                                                                </ControlTemplate.Triggers>
                                                            </ControlTemplate>
                                                        </ScrollBar.Template>
                                                    </ScrollBar>
                                                </Grid>
                                            </Grid>
                                        </ControlTemplate>
                                    </ScrollViewer.Template>
                                    <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                </ScrollViewer>
                            </Border>
                        </ControlTemplate>
                    </DataGrid.Template>
                </DataGrid>
WPF自定义DataGrid XAML代码
相关标签: C# WPF