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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:42:32+00:00 2026-05-18T10:42:32+00:00

I am quit new to MVVM. So please correct me if I am doing

  • 0

I am quit new to MVVM. So please correct me if I am doing any mistake in implementing MVVM.

In my Model class there are two properties Price and IsChecked.

    public int Price { get; set; }
    public static int _total;

    bool _isChecked;
    public bool IsChecked
    {

        get
        {
            return _isChecked;

        }
        set
        {
            _isChecked = value;

            if (value == true)
            {
                _total+= this.Price;
            }
            else
            {
                _total-= this.Price;
            }


        }
    }

In My ViewModel Class there is a property of Type List <Model > and it is bounded to datagrid in view and another property is Total, which bounded to a textBlock in View.

    public int Total
    {
        get
        {
            return  DocumentStoreModel._total;

        }
        set
        {

        }

    }

DataGrid has a checkBox column and it is bounded with Ischecked property

<DG:DataGridCheckBoxColumn Header="Select" Binding="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ></DG:DataGridCheckBoxColumn>

Now, if user checked the Checkbox from checkbox column in DataGrid then total should be reflected in View.

My ViewModel class is implementing the INotifyPropertyChanged interface.

My qus is,if my model’s property is changing how i can tell it to my viewModel ?

please let me know How i can achieve this.

  • 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-18T10:42:32+00:00Added an answer on May 18, 2026 at 10:42 am

    As you are exposing your Model within your ViewModel, then you need to implement INotifyPropertyChanged in your Model. You however have a problem in that your Total property is static and (afaik) you cant use INotifyPropertyChanged for static properties.
    I would suggest you create a custom event on your model that can be subscribed to on your ViewModel. Here’s an example (you might want to tidy it up a bit).

    public class Model : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        internal static event EventHandler TotalChanged;
        internal static int Total { get; private set;}
    
        private int price;
        public int Price
        {
            get { return price; }
            set
            {
                price = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("Price"));
            }
        }
    
        private bool isChecked;
        public bool IsChecked
        {
            get { return isChecked; }
            set
            {  isChecked = value; 
                if (value)
                    Total += Price;
                else
                    Total -= Price;
                if (TotalChanged != null)
                    TotalChanged(this, EventArgs.Empty);
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs("IsChecked"));
            }
        }
    }
    
    public class MainViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public int Total
        {
            get { return Model.Total;  }
        }
    
        public MainViewModel()
        {
            Model.TotalChanged += TotalChanged;
        }
    
        private void TotalChanged(object sender, EventArgs e)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("Total"));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use quit functionality in my android application. Is there any way
im quit new to the ASP.Net MVC World. But i can't find any examples
I am inserting a new Folder entity into my model object context (MOC), that
Does any one know how to insert only new row to the existing table
I have a QSystemTrayIcon subclass. Inside it, I have: quitAction = new QAction(tr(&Quit), m_parent);
My custom error messages quit working somewhere along the way and I'm getting this
I just want to quit as fast as possible, before the nibs are loaded.
I need to quit firefox and restart it in order for the applet to
Will it auto release when the user quit the application? or it will stay
This is really why I quit using Hibernate to manage my relationships for me.

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.