【问题标题】:Change cell size to a WPF DataGrid?将单元格大小更改为 WPF DataGrid?
【发布时间】:2012-04-17 18:02:18
【问题描述】:

是否可以更改 WPF System.Windows.Controls.DataGrid 的单元格大小?

比如说,我希望我的所有单元格的大小都是 (100 x 50)。

【问题讨论】:

    标签: .net wpf wpfdatagrid


    【解决方案1】:
    <DataGrid ...
        <DataGrid.CellStyle>
            <Style TargetType="DataGridCell">
                <Setter Property="Width" Value="100"/>
               <Setter Property="Height" Value="50"/>
            </Style>
        </DataGrid.CellStyle>
    

    【讨论】:

      【解决方案2】:

      试试这样的:

          <!--you can set Name and ItemsSource to other values, this is just a sample-->
          <DataGrid x:Name="dataGrid" ItemsSource="{Binding}">
              <DataGrid.CellStyle>
                  <Style TargetType="DataGridCell">
                      <Setter Property="Width" Value="100"/>
                      <Setter Property="Height" Value="50"/>
                  </Style>
              </DataGrid.CellStyle>
          </DataGrid>
      

      【讨论】:

        【解决方案3】:

        您是否尝试过设置 ColumnWidth 和 RowHeight?

         <DataGrid ColumnWidth="100" RowHeight="50"/>
        

        有关设置 DataGrid 样式的更多信息,请访问 Styling Microsoft’s WPF datagrid.

        【讨论】:

          猜你喜欢
          • 2013-05-01
          • 2016-03-29
          • 1970-01-01
          • 1970-01-01
          • 2020-03-27
          • 2015-11-19
          • 1970-01-01
          • 2011-06-29
          • 2023-03-28
          相关资源
          最近更新 更多