【问题标题】:Is it possible to hide a specific ColumnHeader in WPF DataGrid?是否可以在 WPF DataGrid 中隐藏特定的 ColumnHeader?
【发布时间】:2012-10-08 05:41:12
【问题描述】:

我想知道是否可以在 DataGrid 中隐藏特定的列标题,例如我想隐藏第 2 列的标题,因为我需要在其中放置一个 Contol,并且不再需要标题。

【问题讨论】:

    标签: wpf wpfdatagrid datatemplate controltemplate


    【解决方案1】:

    不确定我是否理解正确。 是的,您可以通过以下方式隐藏它:

    您可以将任何您想要的内容放入 column2 的标题中,据我所知,它只需要 UIElement。你可以把计算器等放在那里。根据你的需要切换它。

    【讨论】:

      【解决方案2】:

      尝试应用 DataGridColumnHeader 样式

          <Style x:Key="CustomHeader" TargetType="{x:Type DataGridColumnHeader}">
          <Setter Property="Template">
              <Setter.Value>
                  <ControlTemplate TargetType="DataGridColumnHeader">
                      <Grid  >
                          <!-- Put the code for the controller here -->
                      </Grid>
                  </ControlTemplate>
              </Setter.Value>
          </Setter>
      </Style>
      

      如果您不想显示列标题,请不要在样式中包含&lt;ContentPresenter /&gt; 标签

      【讨论】:

        猜你喜欢
        • 2020-12-08
        • 2017-02-06
        • 2011-04-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-30
        • 2019-11-10
        相关资源
        最近更新 更多