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>

  • 相关阅读:
    mybatis设置select返回HashMap,字段值为null时,不会保存key
    copyProperties 忽略null值字段
    动态新增表单
    页面时时刷新数据
    FormData 传List对象集合到后台
    linux常用命令总结
    Linux部署安装JDK
    yum安装nginx
    01_Python基础
    Nginx防盗链
  • 原文地址:https://www.cnblogs.com/mqxs/p/14555004.html
Copyright © 2011-2022 走看看