1

I have the follwoing listview in my xaml:

    <ListView  Name="listView1">
        <ListView.View>
            <GridView>
                    <GridViewColumn Width="Auto" Header="Name"  
         DisplayMemberBinding="{Binding nombre}" />
                <GridViewColumn Width="200" Header="LastName"  
         DisplayMemberBinding="{Binding razonSocial}" />

         // etc....

I have an ObservableCollection binded to a listview. I created the binding behind code. So any changes that I make to that collection will be reflected on the listview. Also if I want to sort the listview I will just sort the ObservableCollection.

I sort the listview when the user clicks on a gridviewcolumnheader as:

        listView1.AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler((a, b) =>
        {

            // check to see what column header was clicked
            string bindingProperty =
               ((Binding)(((GridViewColumnHeader)(b.OriginalSource)).Column.DisplayMemberBinding)).Path.Path;




             // using dyniamic linq libraries or the example located at
             //  http://stackoverflow.com/a/233505/637142
             // I will be able to sort my collection of objects by nowing the property name


        }));

Anyways I will like to apply a diferent style to the GridViewColumnHeader that was just clicked. I believe there should be already an existing template.

I am looking for something like:

   GridViewColumnHeader a = "gridviewColumnHeader that was clicked"

   a.Style = "orderByAscGridViewColumnTemplate"
Tono Nam
  • 34,064
  • 78
  • 298
  • 470

1 Answers1

3

Code Behind:

        listView1.AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler((a, e) =>
        {


            GridViewColumnHeader headerClicked =
              e.OriginalSource as GridViewColumnHeader;

            headerClicked.Column.HeaderTemplate =
                      Resources["HeaderTemplateArrowUp"] as DataTemplate;

xaml:

<UserControl.Resources>

    <DataTemplate x:Key="HeaderTemplateArrowUp">
        <DockPanel>
            <TextBlock HorizontalAlignment="Center" Text="{Binding}"/>
            <Path x:Name="arrow"
       StrokeThickness = "1"                                     
       Fill            = "gray"
       Data            = "M 5,10 L 15,10 L 10,5 L 5,10"/>
        </DockPanel>
    </DataTemplate>


</UserControl.Resources>
Tono Nam
  • 34,064
  • 78
  • 298
  • 470