none
ListView 自定义列如何让header看不到? RRS feed

  • 问题

  • <ListView x:Name="listViewErroDiagnose">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn DisplayMemberBinding="{Binding OccuringTime}">
                                <GridViewColumn.HeaderTemplate>
                                    <DataTemplate>
                                        <Label Height="0" >aaa</Label>
                                    </DataTemplate>
                                </GridViewColumn.HeaderTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>

    如上,header貌似还是会显示出来,如何让它看不到阿?

    2011年10月19日 5:40

答案

  • 你这样只能隐藏掉那个Label,如果你要把整个 列头 那一行都隐藏掉,你应该这样:

        <ListView ItemsSource="{Binding}">
          <ListView.Resources>
            <Style TargetType="{x:Type GridViewColumnHeader}">
              <Setter Property="Visibility" Value="Collapsed"/>
            </Style>
          </ListView.Resources>
          <ListView.View>
            <GridView>
              <GridView.Columns>
                <GridViewColumn DisplayMemberBinding="{Binding Name}">
                </GridViewColumn>
              </GridView.Columns>
            </GridView>
          </ListView.View>
        </ListView>
    


    或者

                <GridViewColumn DisplayMemberBinding="{Binding Name}">
                  <GridViewColumn.HeaderContainerStyle>
                    <Style TargetType="{x:Type GridViewColumnHeader}">
                      <Setter Property="Visibility" Value="Collapsed"/>
                    </Style>
                  </GridViewColumn.HeaderContainerStyle>
                </GridViewColumn>

    只隐藏这一列,其他列还是会有占位。

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年10月19日 7:50
    版主