`

自定义DataGrid样式

 
阅读更多
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <!--自定义DataGrid样式-->
    <Style x:Key="CustomDataGrid" TargetType="DataGrid">
        <Setter Property="SnapsToDevicePixels" Value="True"></Setter>
        <Setter Property="AutoGenerateColumns" Value="False"></Setter>
        <Setter Property="CanUserResizeRows" Value="False"></Setter>
        <Setter Property="CanUserAddRows" Value="False"></Setter>
        <Setter Property="SelectionMode" Value="Single"></Setter>
        <Setter Property="CanUserSortColumns" Value="True"></Setter>
        <Setter Property="HorizontalGridLinesBrush" Value="Gray"></Setter>
        <Setter Property="VerticalGridLinesBrush" Value="Gray"></Setter>
        <Setter Property="BorderBrush" Value="Gray"></Setter>
        <Setter Property="ColumnWidth" Value="auto"></Setter>
        <Setter Property="IsReadOnly" Value="True"></Setter>
        <Setter Property="RowHeight" Value="22"></Setter>
       

        <Setter Property="RowHeaderStyle">
            <Setter.Value>
                <Style x:Name="CustomDataGridRowHeader" TargetType="DataGridRowHeader">
                    <!--
                    <Setter Property="Background" Value="#DDD"/>
                    <Setter Property="Padding" Value="5,0,5,0"></Setter>
                    -->
                    <Setter Property="Width" Value="Auto"></Setter>
                    <Setter Property="MinWidth" Value="0"></Setter>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="ColumnHeaderStyle">
            <Setter.Value>
                <Style x:Name="CustomDataGridColumnHeader" TargetType="DataGridColumnHeader">
                    <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
                    <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="CellStyle">
            <Setter.Value>
                <Style x:Name="CustamDataGridCell" TargetType="DataGridCell">
                    <Setter Property="BorderThickness" Value="0"></Setter>
                </Style>
            </Setter.Value>
        </Setter>
    </Style>


    <!--设置DataGrid单元格垂直居中显示-->
    <Style x:Key="dgCellTextBlock" TargetType="TextBlock">
        <Setter Property="Padding" Value="2,3,2,0"></Setter>
        <Setter Property="TextAlignment" Value="Center"/>
    </Style>

    <!--设置DataGrid单元格数字靠右显示-->
    <Style x:Key="dgCellTextBlockRight" TargetType="TextBlock">
        <Setter Property="Padding" Value="2,3,3,0"></Setter>
        <Setter Property="TextAlignment" Value="Right"/>
    </Style>

    <Style x:Key="FQCustomDataGrid" TargetType="DataGrid">
        <Setter Property="BorderThickness" Value="0"></Setter>
        <Setter Property="BorderBrush" Value="Black"></Setter>
        <Setter Property="GridLinesVisibility" Value="None"></Setter>
        <Setter Property="SnapsToDevicePixels" Value="True"></Setter>
        <Setter Property="AutoGenerateColumns" Value="False"></Setter>
        <Setter Property="CanUserResizeRows" Value="False"></Setter>
        <Setter Property="CanUserAddRows" Value="False"></Setter>
        <Setter Property="SelectionMode" Value="Single"></Setter>
        <Setter Property="CanUserSortColumns" Value="False"></Setter>
        <Setter Property="ColumnWidth" Value="auto"></Setter>
        <Setter Property="IsReadOnly" Value="True"></Setter>
        <Setter Property="RowHeight" Value="22"></Setter>
        <Setter Property="HeadersVisibility" Value="Column"></Setter>
        <Setter Property="Background" Value="Black"></Setter>
        <Setter Property="RowHeaderStyle">
            <Setter.Value>
                <Style x:Name="FQCustomDataGridRowHeader" TargetType="DataGridRowHeader">
                   
                    <!--<Setter Property="Background" Value="Black"/>-->
                    <!--<Setter Property="Padding" Value="5,0,5,0"></Setter>-->
                   
                    <Setter Property="Width" Value="Auto"></Setter>
                    <Setter Property="MinWidth" Value="0"></Setter>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="ColumnHeaderStyle">
            <Setter.Value>
                <Style x:Name="DataGridColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}"  >
                    <Setter Property="Height" Value="25"></Setter>
                    <Setter Property="Background" Value="Black" />
                    <Setter Property="Foreground" Value="White" />
                    <Style.Triggers>
                        <!--<Trigger Property="SortDirection" Value="{x:Null}">
                            <Setter Property="Background" Value="{DynamicResource DataGridHeaderBackgroundBrush}" />
                            <Setter Property="BorderBrush"  Value="Transparent" />
                        </Trigger>-->
                        <!--<MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="True" />
                                <Condition Property="SortDirection" Value="{x:Null}" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" Value="{StaticResource DataGridHeaderMouseOverBackgroundBrush}" />
                            <Setter Property="BorderBrush" Value="{StaticResource DataGridHeaderBorderBrush}" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="true" />
                                <Condition Property="SortDirection" Value="{x:Null}" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" Value="{StaticResource DataGridHeaderMouseOverBackgroundBrush}" />
                            <Setter Property="BorderBrush" Value="{StaticResource DataGridHeaderBorderBrush}" />
                        </MultiTrigger>-->
                        <Trigger Property="SortDirection" Value="Ascending">
                            <Setter Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <Grid x:Name="GridContentTemplate">
                                            <Label Background="Black" Foreground="White" Content="{TemplateBinding Content}"/>
                                            <Path x:Name="SortArrowUp" Visibility="Visible" Data="M0,0 L1,0 L0.5,1 z" Stretch="Fill"  Grid.Column="2" Width="8" Height="6" Fill="Red" Margin="0,0,50,0" VerticalAlignment="Center" RenderTransformOrigin="1,1" />
                                        </Grid>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="SortDirection" Value="Descending">
                            <Setter Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <Grid x:Name="GridContentTemplate">
                                            <Label Background="Black" Foreground="White" Content="{TemplateBinding Content}"/>
                                            <Path x:Name="SortArrow" Visibility="Visible" Data="M0,0 L1,0 L0.5,1 z" Stretch="Fill"  Grid.Column="2" Width="8" Height="6" Fill="White" Margin="0,0,50,0" VerticalAlignment="Center" RenderTransformOrigin="1,1" />
                                        </Grid>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Setter.Value>
        </Setter>

        <!--<Setter Property="ColumnHeaderStyle">
            <Setter.Value>
                <Style x:Name="FQCustomDataGridColumnHeader" TargetType="DataGridColumnHeader">
                    <Setter Property="SnapsToDevicePixels" Value="True" />
                    <Setter Property="Padding" Value="5,0,5,0"></Setter>
                    <Setter Property="MinWidth" Value="0" />
                    <Setter Property="MinHeight" Value="28" />
                    <Setter Property="Foreground" Value="Green" />
                    <Setter Property="Background" Value="Black"/>
                    <Setter Property="FontSize" Value="14" />

                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <Grid x:Name="GridContentTemplate">
                                    <Label Background="Black" Foreground="White" Content="{TemplateBinding Content}"/>
                                    <Path x:Name="SortArrow" Visibility="Collapsed" Data="M0,0 L1,0 L0.5,1 z" Stretch="Fill"  Grid.Column="2" Width="8" Height="6" Fill="White" Margin="0,0,50,0" VerticalAlignment="Center" RenderTransformOrigin="1,1" />
                                    <Path x:Name="SortArrowUp" Visibility="Collapsed" Data="M0,0 L1,0 L0.5,1 z" Stretch="Fill"  Grid.Column="2" Width="8" Height="6" Fill="Red" Margin="0,0,50,0" VerticalAlignment="Center" RenderTransformOrigin="1,1" />
                                </Grid>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                    <Style.Triggers>
                        <Trigger Property="SortDirection" Value="Descending">

                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Setter.Value>
        </Setter>-->

       
       
        <!--<Setter Property="ColumnHeaderStyle">
            <Setter.Value>
                <Style x:Name="FQCustomDataGridColumnHeader" TargetType="DataGridColumnHeader">
                    <Setter Property="SnapsToDevicePixels" Value="True" />
                    <Setter Property="Padding" Value="5,0,5,0"></Setter>
                    <Setter Property="MinWidth" Value="0" />
                    <Setter Property="MinHeight" Value="28" />
                    <Setter Property="Foreground" Value="Green" />
                    <Setter Property="Background" Value="Black"/>
                    <Setter Property="AllowDrop" Value="True"></Setter>
                    <Setter Property="Cursor" Value="Hand"></Setter>
                    <Setter Property="FontSize" Value="14" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="DataGridColumnHeader">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <ContentPresenter  Margin="0,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                    <Path x:Name="SortArrow" Visibility="Visible" Data="M0,0 L1,0 L0.5,1 z" Stretch="Fill"  Grid.Column="2" Width="8" Height="6" Fill="White" Margin="0,0,50,0"
                    VerticalAlignment="Center" RenderTransformOrigin="1,1" />
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Height" Value="25"/>
                </Style>
            </Setter.Value>
        </Setter>-->
        <Setter Property="CellStyle">
            <Setter.Value>
                <Style x:Name="FQCustamDataGridCell" TargetType="DataGridCell">
                    <Style.Setters>
                        <Setter Property="Background" Value="Black"/>
                        <Setter Property="Foreground" Value="Red"/>
                        <Setter Property="BorderThickness" Value="0"></Setter>
                    </Style.Setters>
                    <Style.Triggers>
                        <!--<Trigger Property="IsMouseOver" Value="True">
                            <Trigger.Setters>
                                <Setter Property="Background" Value="Gold"></Setter>
                            </Trigger.Setters>
                        </Trigger>-->
                        <Trigger Property="IsSelected" Value="True">
                            <Trigger.Setters>
                                <Setter Property="Background" Value="BlueViolet"></Setter>
                            </Trigger.Setters>
                        </Trigger>
                    </Style.Triggers>
                   
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="RowStyle">
            <Setter.Value>
                <Style TargetType="DataGridRow">
                    <Style.Setters>
                        <Setter Property="Background" Value="Black"/>
                    </Style.Setters>
                    <Style.Triggers>
                        <!--<Trigger Property="IsMouseOver" Value="True">
                            <Trigger.Setters>
                                <Setter Property="Background" Value="Gold"></Setter>
                            </Trigger.Setters>
                        </Trigger>-->
                        <Trigger Property="IsSelected" Value="True">
                            <Trigger.Setters>
                                <Setter Property="Background" Value="BlueViolet"></Setter>
                            </Trigger.Setters>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Setter.Value>
        </Setter>
      
    </Style>

    <Style x:Key="FQDataGridCellBase" TargetType="DataGridCell">
        <Style.Setters>
            <Setter Property="Background" Value="Black"/>
            <Setter Property="BorderThickness" Value="0"></Setter>
        </Style.Setters>
        <Style.Triggers>
            <!--<Trigger Property="IsMouseOver" Value="True">
                <Trigger.Setters>
                    <Setter Property="Background" Value="Gold"></Setter>
                </Trigger.Setters>
            </Trigger>-->
            <Trigger Property="IsSelected" Value="True">
                <Trigger.Setters>
                    <Setter Property="Background" Value="BlueViolet"></Setter>
                </Trigger.Setters>
            </Trigger>
        </Style.Triggers>
    </Style>
    <Style x:Key="FQDataGridRowBase" TargetType="DataGridRow">
        <Style.Setters>
            <Setter Property="Background" Value="Black"/>
        </Style.Setters>
        <Style.Triggers>
            <!--<Trigger Property="IsMouseOver" Value="True">
                            <Trigger.Setters>
                                <Setter Property="Background" Value="Gold"></Setter>
                            </Trigger.Setters>
                        </Trigger>-->
            <Trigger Property="IsSelected" Value="True">
                <Trigger.Setters>
                    <Setter Property="Background" Value="BlueViolet"></Setter>
                </Trigger.Setters>
            </Trigger>
        </Style.Triggers>
    </Style>

    <!--设置DataGrid单元格前景色Yellow-->
    <Style x:Key="dgCellTextBlockForegroundYellow" TargetType="TextBlock">
        <Setter Property="Foreground" Value="Yellow"></Setter>
    </Style>

    <!--设置DataGrid单元格前景色Yellow-->
    <Style x:Key="dgCellTextBlockForegroundWhite" TargetType="TextBlock">
        <Setter Property="Foreground" Value="White"></Setter>
    </Style>
</ResourceDictionary>
分享到:
评论

相关推荐

    自定义的 DataGrid样式

    自定义DataGrid样式可以帮助开发者根据应用程序的需求调整控件的外观和交互方式,使其更符合用户界面的设计规范。下面我们将深入探讨如何自定义DataGrid样式及其相关的知识点。 1. **创建资源字典** 自定义...

    自定义Datagrid

    在IT领域,自定义Datagrid是一项常见的需求,尤其是在开发数据密集型应用时。Datagrid是一种用于展示和操作表格数据的控件,它允许用户以视觉上友好的方式查看和交互大量结构化的信息。本资源围绕C#语言环境下的...

    wpf DataGrid 自定义样式!

    本篇文章将详细介绍如何利用 WPF 的 `ControlTemplate` 对 `DataGrid` 进行自定义样式,以及如何为特定行或列定制样式。 首先,`ControlTemplate` 是 WPF 中的一个重要概念,它允许我们完全重新定义控件的外观。...

    WPF中自定义复杂DataGrid列样式

    WPF中DataGrid控件有时需要在一列中显示多个字段数据,并实现一定的排版,本示例即为解决此类问题提供参考。

    Grid(6)[自定义DataGrid-强制显示分列线(在不显示列头时)]

    "Grid(6)[自定义DataGrid-强制显示分列线(在不显示列头时)]"这个标题表明我们正在讨论一个关于数据网格(DataGrid)的自定义实现,具体是针对Flex或Flash环境中的MXML组件。这里的“Grid(6)”可能指的是该系列教程的...

    Flex 自定义Datagrid的ItemRender

    本文将深入探讨如何在Flex中自定义Datagrid的ItemRender,以实现按钮、单选、复选和日期等控件的集成。 首先,我们需要了解ItemRender的基本概念。ItemRenderer是Flex提供的一种机制,允许开发者为数据网格中的每一...

    Mobile下自定义DataGrid控件源代码

    总的来说,这个项目涉及了自定义`DataGrid`控件的实现,通过数据集与数据库进行数据绑定,同时利用自定义列样式实现编辑、下拉列表和选择框等功能。开发者需要对.NET Compact Framework、Windows Forms以及数据库...

    自定义DataGrid分页块完美实现

    本话题将深入探讨如何自定义DataGrid的分页块,实现一个完美的分页效果。 DataGrid的分页功能默认提供了一些基本选项,如每页显示的记录数和页码导航。然而,这些默认设置可能无法满足所有需求,比如自定义样式、...

    flex 自定义dataGrid渲染器.根据数据变色

    总的来说,通过自定义DataGrid的渲染器,我们可以实现更灵活的数据显示效果。在这个例子中,我们学会了如何根据数据的值动态改变单元格的颜色,增强了用户界面的交互性和可视化效果。这种技术在数据监控、报表展示等...

    DataGrid样式.rar

    文件列表“DataGrid样式”可能是一个项目文件,里面可能有XAML和C#代码,用于展示如何自定义DataGrid样式、实现表头合并以及分页功能。通过研究这些代码,开发者可以更好地理解如何在实际项目中应用这些技术。 总结...

    自定义datagrid

    在本话题中,我们将探讨如何自定义网页风格的`datagrid`,使其更适应网络开发的需求。 首先,让我们了解`datagrid`的基本概念。`datagrid`通常是一个JavaScript库或框架中的组件,如jQuery UI、ExtJS或AngularJS等...

    DataGrid自定义列标题

    综上所述,通过各种方式我们可以实现DataGrid的自定义列标题,包括文本、样式、交互性和动态调整列宽等特性,以满足不同场景下的需求。在实际项目中,根据具体业务逻辑和界面设计灵活运用这些方法,能够打造出更加...

    给DataGrid自定义Header功能

    在提供的`CustomDataGridHeader`文件中,可能包含了实现这一功能的具体代码示例,包括自定义HeaderRenderer组件的定义、配置DataGrid的列定义以及可能的样式和交互逻辑。通过查看和学习这个示例,你可以更深入地了解...

    WPF DataGrid样式

    1. **整体外观**:你可以自定义DataGrid的整体背景色、边框颜色、边框宽度等。这可以通过设置DataGrid的Background、BorderBrush和BorderThickness属性来实现。 2. **单元格样式**:DataGrid中的每个单元格都可以有...

    as3 datagrid flash 自定义检索程序

    自定义Datagrid列及列头意味着开发者可以根据需求调整列的显示样式,如宽度、字体、颜色等。此外,还可以定制列头的功能,如排序、过滤等。内容对齐方式的设置则涉及CSS样式,可以控制单元格内容的水平和垂直对齐。 ...

    wpf 自定义ComBoBox带DataGrid

    本项目“wpf 自定义ComBoBox带DataGrid”旨在实现一个具有组合框(ComboBox)与数据网格(DataGrid)功能结合的控件,这种控件在很多业务场景下都非常实用,例如在选择数据项时提供详细信息预览。 **组合框...

    WPF.DataGrid.MergeRow

    DataGrid的行单元格合并功能并不是默认支持的,因此通常需要通过自定义样式、模板和数据绑定来实现。下面将详细介绍如何在WPF中实现DataGrid的行单元格合并,以及如何利用提供的"TestDataGridMergeCell"文件进行操作...

    silverlight Datagrid 样式

    总结,"好看的Silverlight Datagrid样式"涉及到的内容广泛,包括但不限于DataGrid控件的基础知识、样式和模板的定制、DataGridTextColumn的使用以及如何通过动画和性能优化提升用户体验。通过对这些知识点的掌握和...

    WPFDataGrid样式

    本篇将深入探讨`WPF DataGrid`的样式定制,以及如何通过提供的文件名如`WPF-DataGrid.txt`、`WPF-DataGrid1.txt`和`WPF-DataGrid2.txt`来学习和理解相关知识。 1. **基础样式** `DataGrid`的外观可以通过设置`...

Global site tag (gtag.js) - Google Analytics