Solved

Modular context menu for Xaml - C#

Posted on 2008-10-03
1
2,625 Views
Last Modified: 2013-12-17
Got a context menu to pop up successfully on a ListView in Xaml using this code:
        <ListView Name="lvwCustomersList" Grid.Row="1" BorderBrush="Gray"
                  BorderThickness=".5" ItemsSource="{Binding Path=.}"
                  Height="106" Grid.RowSpan="2" VerticalAlignment="Top" >
            <ListView.ContextMenu>
                <ContextMenu>
                    <!--<menu:lvwRightClick/>-->
                    <MenuItem Header="New" Name="cmnuNew" Click="cmnuNew_Click"/>
                    <MenuItem Header="Delete" Name="cmnuDelete" Click="cmnuDelete_Click"/>
                    <MenuItem Header="Update" Name="cmnuUpdate" Click="cmnuUpdate_Click"/>
                    <Separator />
                    <MenuItem Header="Cancel" Name="cmnuCancel" Click="cmnuCancel_Click"/>
                </ContextMenu>
            </ListView.ContextMenu>
In addition, ALL the click events work in this code.

However, I what I want to do is to make this context menu call more modular
    xmlns:menu="clr-namespace:XXXX.YYYY.Module.Views.Menus"
                <ContextMenu>
                     <menu:lvwRightClick/>
                </ContextMenu>

When I do this, I get a context menu displayed but it's totally blank - code for lvwRightClick:
<UserControl x:Class="Multifamily.Security.Module.Views.Menus.lvwRightClick"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="Auto" Width="Auto">
    <ListView>
        <ListView.ContextMenu>
             <ContextMenu>
                    <MenuItem Header="New" Name="cmnuNew" Click="cmnuNew_Click"/>
                    <MenuItem Header="Delete" Name="cmnuDelete" Click="cmnuDelete_Click"/>
                    <MenuItem Header="Update" Name="cmnuUpdate" Click="cmnuUpdate_Click"/>
                    <Separator />
                    <MenuItem Header="Cancel" Name="cmnuCancel" Click="cmnuCancel_Click"/>
            </ContextMenu>
        </ListView.ContextMenu>
    </ListView>
</UserControl>
0
Comment
Question by:Marvin_Rowe
1 Comment
 

Accepted Solution

by:
Marvin_Rowe earned 0 total points
ID: 22669809
Answered own question:
Xaml for context menu:
 <ContextMenu x:Class="XXXX.Security.Module.Views.Menus.lvwRightClick"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <MenuItem Header="New" Name="cmnuNew" Click="cmnuNew_Click"/>
    <MenuItem Header="Delete" Name="cmnuDelete" Click="cmnuDelete_Click"/>
    <MenuItem Header="Update" Name="cmnuUpdate" Click="cmnuUpdate_Click"/>
    <Separator />
    <MenuItem Header="Cancel" Name="cmnuCancel" Click="cmnuCancel_Click"/>
</ContextMenu>

Xaml for ListView with generic context menu:
<UserControl x:Class="XXXX.Security.Module.Views.ListViews.lvwCustomers"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:menu="clr-namespace:XXXX.Security.Module.Views.Menus"      
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Name="Customers_Base" Height="Auto" Width="Auto">
    <Grid>
        <ListView Name="lvwCustomersList" Grid.Row="1" BorderBrush="Gray"
                  BorderThickness=".5" ItemsSource="{Binding Path=.}"
                  Height="106" Grid.RowSpan="2" VerticalAlignment="Top" >
            <ListView.ContextMenu>
                <menu:lvwRightClick/>
            </ListView.ContextMenu>
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to prevent website from publishing with errors 9 49
Sent email using Shared Mailbox from outlook in C# 5 25
.NET 2008 VB and C# 6 28
C# Gridview 1 33
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question