CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2009

    Using common Menu for WPF ListView Header


    We have a requirement for a a WPF ListView Header which has primary, secondary and tertiary
    levels of sorting. I am implementing this Header as a Menu. I want to use a common header across the different columns and enable/disable items in the menu based on the state of the application. For example, secondary sorting is disabled until primary sorting is selected.

    So far, I have written a data template for the ListView header but that forces me to handle
    each header's state separately as each header has its own menu.

    Here is my code. Does anyone know what is the best approach for such a scenario:

    <DataTemplate x:Key="myHeaderTemplate">
    <ColumnDefinition Width="*"></ColumnDefinition>
    <MenuItem Header="{Binding}" Icon="">
    <MenuItem Header="Primary Sort Ascending" Click="MenuItem_Click_1"></MenuItem>
    <MenuItem Header="Primary Sort Descending" Click="MenuItem_Click_1"></MenuItem>
    <MenuItem Header="Secondary Sort Ascending" Click="MenuItem_Click_1" IsEnabled="False"></MenuItem>
    <MenuItem Header="Secondary Sort Descending" Click="MenuItem_Click_1" IsEnabled="False"></MenuItem>
    <MenuItem Header="Tertiary Sort Ascending" Click="MenuItem_Click_1" IsEnabled="False"></MenuItem>
    <MenuItem Header="Tertiary Sort Descending" Click="MenuItem_Click_1" IsEnabled="False"></MenuItem>

    <GridView ColumnHeaderTemplate="{StaticResource myHeaderTemplate}">
    <GridViewColumn Header="Check" CellTemplate="{StaticResource CheckTemplate}"/>
    <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"/>
    <GridViewColumn Header="State" CellTemplate="{StaticResource ImageTemplate}"/>
    <GridViewColumn Width="auto" Header="Description" DisplayMemberBinding="{Binding Path=Description}"/>
    <GridViewColumn Header="Created By" DisplayMemberBinding="{Binding Path=CreatedBy}"/>
    <GridViewColumn Header="Created Date" DisplayMemberBinding="{Binding Path=CreatedDate,Converter={StaticResource dateConverter}}"/>
    <GridViewColumn Header="Modified By" DisplayMemberBinding="{Binding Path=ModifiedBy}"/>
    <GridViewColumn Header="Modified Date" DisplayMemberBinding="{Binding Path=ModifiedDate,Converter={StaticResource dateConverter}}"/>

    Thanks in advance,


  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004

    Re: Using common Menu for WPF ListView Header

    Not sure I follow, but can you handle the ContextMenuOpening event and build the menu items dynamically?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.