Print Page | Close Window

propertychanged event for mvvm

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2002
Printed Date: 21-Apr-2026 at 3:49pm


Topic: propertychanged event for mvvm
Posted By: hueha
Subject: propertychanged event for mvvm
Date Posted: 23-Jul-2010 at 1:47pm
I'm trying to implement mvvm in my class.  I want to catch the propertychanged event in the entity class and bubble it up.

Using your simplecombobox project as an example I added the following class to the simplecombodemo project.  Am I catching the propertychanged event correctly?  Because I am not getting the propertychanged event when I do Class1.Employee.Address="abc"


using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using IdeaBlade.EntityModel;

namespace SimpleComboDemo
{
    public class Class1
    {
        private Employee myEmployee;
        public string propname;
        public Employee Employee
        {
            get { return myEmployee; }
        }

        public Class1()
        {
            myEmployee = new Employee();
            myEmployee.PropertyChanged += new PropertyChangedEventHandler(MyCust_PropertyChanged);
        }
        private void MyCust_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            var propchange = e.PropertyName;
        }
    }
}





Replies:
Posted By: hueha
Date Posted: 23-Jul-2010 at 1:59pm
Ok it seems it is firing for edits when I load the object from the database but not when it's fresh new object.  Is this a bug?


Posted By: ting
Date Posted: 23-Jul-2010 at 3:08pm

The PropertyChanged events do not fire when the entity is in a detached state (this is the state a new entity is in before adding it to an EntityManager).  Once you call entityManager.AddEntity(myEmployee) it will start firing.




Print Page | Close Window