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 6193577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:08:36+00:00 2026-05-24T03:08:36+00:00

I have been trying to create a fairly simple application in WPF following the

  • 0

I have been trying to create a fairly simple application in WPF following the MVVM development pattern but I have been going crazy over how difficult it seems to be to do simple things. I have already created this app in Forms and had it successfully running, but my boss requested I rewrite the interface in WPF as a demo of the technology. I decided to try to follow as many best practices as I can in order to make the app and code as educational as possible. My current dilemma is using a listbox to run some code every time the selection changes. I’m ready to just use the code-behind with an event to call the method on the view-model. To me this seems to still be essentially MVVM since no logic is executing. Thanks for any help/insight.

  • 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-24T03:08:37+00:00Added an answer on May 24, 2026 at 3:08 am

    You can do that simply binding selecteditem property of listbox… on selection change a setter in the view model will be called and you can do what ever you want…

    Here is a sample which will help you

    XAML

      <Grid Canvas.Left="0" Canvas.Bottom="0" Height="300" Width="300" Background="Bisque">
                <ListBox ItemsSource="{Binding Employes}" SelectedItem="{Binding SelectedEmploye}"/>
            </Grid>
    

    View Model

    public  class ViewModel : ViewModelBase
        {
            private List<Employee> _employes;
    
            public List<Employee> Employes
            {
                get { return _employes; }
                set { _employees = value; OnPropertyChanged("Employes"); }
            }
            private Employee _selectedEmploye;
    
            public Employee SelectedEmploye
            {
                get { return _selectedEmploye; }
                set
                {
                    _selectedEmployee = value;
                    OnPropertyChanged("SelectedEmploye");
                }
            }
    
        }
    

    View model base

    public  class ViewModelBase : INotifyPropertyChanged
        {
            protected virtual void OnPropertyChanged(string propertyName)
            {
                if (this.PropertyChanged != null)
                {
                    this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                }
            }
            public event PropertyChangedEventHandler PropertyChanged;
        }
    

    Employee Class

    public class Employee : ViewModelBase
        {
            private string _name;
            public string Name
            {
                get { return _name; }
                set { _name = value; }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to create a simple calculator. Using PHP I managed to
I have been trying to create a directory in /sdcard programmatically, but it's not
I am writing a google reader application and have been trying to create the
I'm fairly new to Compass, but I have been trying to use Compass in
I have been trying to create a simple app that parse an entire channel
I have been trying to create a torrent site but I'm stuck with the
I have been trying to explain the difference between switch statements and pattern matching(F#)
I am trying to create a simple 3-D app for android that will have
I have been trying to create a timer program with VB 2010 to the
Over the past few days I have been trying to create/run a project 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.