Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 252571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:41:20+00:00 2026-05-11T21:41:20+00:00

I am developing a WPF app using MVVM and need some help. for the

  • 0

I am developing a WPF app using MVVM and need some help.

for the View of my AddressesViewModel I have a usercontrol with a listview. I would like to execute a command found in the AddressesViewModel from the contextmenu of the listViewItem. Because I’m opening a ContextMenu it is not found in the visual tree(I read that somewhere).

Here is the View markup:

    <UserControl>
        <ListView Name="lstAddress"
                        ItemsSource="{Binding Path=Addresses}" 
                        HorizontalAlignment="Stretch" MinHeight="150" MinWidth="100">
            <ListView.Resources>
                <ContextMenu x:Key="ItemContextMenu">
                    <MenuItem Header="Add Address"/>
                </ContextMenu>
            </ListView.Resources>
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Address" DisplayMemberBinding="{Binding Path=Address}/>
                    <GridViewColumn Header="City" DisplayMemberBinding="{Binding Path=City}"/>
                </GridView>
            </ListView.View>
            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
                    <Setter Property="ContextMenu" Value="{StaticResource ItemContextMenu}"/>
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>
    </UserControl>

Here is the ViewModel classes:

public class AddressesViewModel
{
    public List<AddressViewModel> Addresses { get; set; }

    public ICommand AddAddressCommand { get; set; }
}

public class AddressViewModel
{
    public String Address { get; set; }
    public String City { get; set; }
    public String State { get; set; }
    public String Zip { get; set; }
}

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:41:21+00:00Added an answer on May 11, 2026 at 9:41 pm

    If your MenuItem looks like this, it should work for you:

                    <MenuItem Header="Add Address" 
                              Command="{Binding DataContext.AddAddressCommand, 
                                    RelativeSource={RelativeSource FindAncestor, 
                                        AncestorType={x:Type ListView}}}"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 513k
  • Answers 513k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer isspace is also a template in C++ which accepts a… May 16, 2026 at 5:51 pm
  • Editorial Team
    Editorial Team added an answer Go to the Visual Studio command line and do the… May 16, 2026 at 5:51 pm
  • Editorial Team
    Editorial Team added an answer How about this...? select case when datepart(Hh, dt) >= 5… May 16, 2026 at 5:51 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm developing a WPF app using MVVM. Most of my views have only xaml
I am developing an application using WPF. The app runs full screen, and I
I've been developing a very large LOB app using my flavor of M-V-VM which
I'm considering developing a WPF application, to be hosted by a legacy Windows app
I am developing a WPF application, and I have created a user control called
I'm developing a system using WPF 4. I pretend to use MVC in development.
I am developing a WPF windows application and am getting into a trouble running
I'm developing an EMR Application as my project. there Im using WCF to transfer
When developing a blackberry app originally, I didn't pay much attention to being able
While developing ASP.NET applications I often need to parse a boolean value given in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.