Link to home
Start Free TrialLog in
Avatar of Marvin Rowe
Marvin RoweFlag for United States of America

asked on

Modular context menu for Xaml - C#

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>
ASKER CERTIFIED SOLUTION
Avatar of Marvin Rowe
Marvin Rowe
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial