Solved

Modular context menu for Xaml - C#

Posted on 2008-10-03
1
2,616 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now