标头没有出现在WPF ListView中

时间:2009-08-06 11:12:03

标签: wpf listview layout

我知道这一定是显而易见的,但我从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?

1 个答案:

答案 0 :(得分:4)

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

<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>

希望这有帮助!