views:

286

answers:

1

I know this must be obvious but I am starting with WPF and I am stuck:

I've the following ListView (in the second row of the main grid on the page), content is showing up but the header is not!

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

Any help appreciated!

EDIT:

Thanks to Roel I was able to find a style in the resourceDictionary casuing this problem:

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

How can I keep that style for the rest of the project without applying it to this specific listView?

+2  A: 

you can overwrite the style just for that listview. this is probably the easiest way:

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

hope this helps!

Roel
thanks for your help! Now I am trying to style the header ... I'll probably post another question :)
JohnIdol
i can save you the trouble:define the ColumnHeaderTemplate on the GridView (not the ListView.GridView!) ;-)
Roel
thanks for pointing me in the right direction!
JohnIdol