zoukankan      html  css  js  c++  java
  • WPF DataGrid 表头单元格居中DataGridCheckBoxColumn居中单击选中

    以下代码实现了DataGrid的一些简单样式功能:

    1、表头居中,表头填充满整个DataGrid

    2、单元格值居中

    3、CheckBox居中,单击选中功能

    <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Items}"  CanUserAddRows="False" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserSortColumns="False" ColumnWidth="*">
                <DataGrid.Columns>
                    <DataGridCheckBoxColumn Header="" Binding="{Binding IsSelected,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="auto">
                        <DataGridCheckBoxColumn.ElementStyle>
                            <Style TargetType="CheckBox">
                                <Setter Property="HorizontalAlignment" Value="Center"></Setter>
                                <Setter Property="VerticalAlignment" Value="Center"></Setter>
                                <Setter Property="Margin" Value="3"></Setter>
                            </Style>
                        </DataGridCheckBoxColumn.ElementStyle>
                    </DataGridCheckBoxColumn>
                    <DataGridTemplateColumn Header="加分项" IsReadOnly="True" Width="*">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock TextWrapping="Wrap" Text="{Binding Name}" ToolTip="{Binding Name}" Margin="3"/>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    <DataGridTextColumn Header="分值" IsReadOnly="True" MinWidth="100" Width="auto" Binding="{Binding Score}">
                        <DataGridTextColumn.ElementStyle>
                            <Style TargetType="TextBlock">
                                <Setter Property="HorizontalAlignment" Value="Center"></Setter>
                                <Setter Property="VerticalAlignment" Value="Center"></Setter>
                                <Setter Property="Margin" Value="3"></Setter>
                            </Style>
                        </DataGridTextColumn.ElementStyle>
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="备注" IsReadOnly="True" MinWidth="100" Width="auto" Binding="{Binding Note}">
                        <DataGridTextColumn.ElementStyle>
                            <Style TargetType="TextBlock">
                                <Setter Property="HorizontalAlignment" Value="Center"></Setter>
                                <Setter Property="VerticalAlignment" Value="Center"></Setter>
                                <Setter Property="Margin" Value="3"></Setter>
                            </Style>
                        </DataGridTextColumn.ElementStyle>
                    </DataGridTextColumn>
                </DataGrid.Columns>
                <DataGrid.ColumnHeaderStyle>
                    <Style TargetType="DataGridColumnHeader">
                        <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
                    </Style>
                </DataGrid.ColumnHeaderStyle>
            </DataGrid>

  • 相关阅读:
    K8S入门学习
    CentOs7安装docker(第二篇)
    使用NFS时的一些问题
    linux的一些基本命令
    centOS7搭建NFS服务器
    ELK日志系统+x-pack安全验证
    如何在网页中用echarts图表插件做出静态呈现效果
    3.29——工作日志
    导航选中,背景变色效果
    网站滚动n个像素后,头部固定
  • 原文地址:https://www.cnblogs.com/mqxs/p/14555004.html
Copyright © 2011-2022 走看看