Solved

Modular context menu for Xaml - C#

Posted on 2008-10-03
1
2,628 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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