Using common Menu for WPF ListView Header
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Using common Menu for WPF ListView Header

Hybrid View

  1. #1
    Join Date
    Jun 2009
    Posts
    1

    Using common Menu for WPF ListView Header

    Hi,

    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">
    <Grid>
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Menu>
    <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>
    </MenuItem>
    </Menu>
    </Grid>
    </DataTemplate>

    <ListView>
    <ListView.View>
    <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}}"/>
    </GridView>
    </ListView.View>
    </ListView>


    Thanks in advance,

    DNG

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

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center