Solved

Modular context menu for Xaml - C#

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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

734 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