【问题标题】:Header not showing up in WPF ListView标题未显示在 WPF ListView 中
【发布时间】:2010-11-17 07:37:58
【问题描述】:

我知道这一定很明显,但我从 WPF 开始但我卡住了:

我有以下 ListView(在页面主网格的第二行),内容显示但标题不显示!

<ListView Grid.Row="1" Name="container" ItemsSource="{Binding MyCollection}" >
   <ListView.View>
      <GridView>
         <GridViewColumn Width="50" Header="A" DisplayMemberBinding="{Binding A}"/>
         <GridViewColumn Width="50" Header="B" DisplayMemberBinding="{Binding B}"/>
         <GridViewColumn Width="50" Header="C" DisplayMemberBinding="{Binding C}"/>            
      </GridView>
   </ListView.View>
</ListView>

任何帮助表示赞赏!

编辑:

感谢 Roel,我能够在 resourceDictionary 中找到导致此问题的样式:

<Style TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListBox}}">
    <Setter Property="BorderBrush" Value="Black"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <ScrollViewer Margin="{TemplateBinding Padding}" VerticalScrollBarVisibility="Visible">
                    <WrapPanel IsItemsHost="True" MinWidth="100" Width="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}">
                    </WrapPanel>
                </ScrollViewer>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

如何在项目的其余部分保留该样式而不将其应用于此特定列表视图?

【问题讨论】:

  • 尝试手动设置行高,检查ListView的顶部是否刚刚被隐藏。
  • 该位似乎没有任何问题,XamlPadX 显示带有标题的列表视图。是否定义了任何可能覆盖样式的资源?
  • 查看编辑,您对资源的看法是正确的!谢谢

标签: wpf listview layout


【解决方案1】:

您可以只为该列表视图覆盖样式。这可能是最简单的方法:

<ListView Grid.Row="1" Name="container" ItemsSource="{Binding MyCollection}"  >
<ListView.Style>
    <Style TargetType="{x:Type ListView}"/>
</ListView.Style>

<ListView.View>
      <GridView>
         <GridViewColumn Width="50" Header="A" DisplayMemberBinding="{Binding A}"/>
         <GridViewColumn Width="50" Header="B" DisplayMemberBinding="{Binding B}"/>
         <GridViewColumn Width="50" Header="C" DisplayMemberBinding="{Binding C}"/>            
      </GridView>
   </ListView.View>
</ListView>

希望这会有所帮助!

【讨论】:

  • 感谢您的帮助!现在我正在尝试设置标题的样式......我可能会发布另一个问题:)
  • 我可以为您省去麻烦:在 GridView 上定义 ColumnHeaderTemplate(不是 ListView.GridView!);-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-28
  • 1970-01-01
  • 2019-06-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多