I am having trouble with Catel's ChildAwareModelBase IsDirty propety not bubbling up to the parent. I thought this worked for me in the past, but it is not functional in my current project and a sample project I just made. I have 3 objects: Parent, Child. and GrandChild. Heirarchy: Parent -> Child -> GrandChild. Each of the objects have a single property Name.
My expectation is that when I update child.Name then parent.IsDirty will be set to true. When I update grandChild.Name then both parent.IsDirty & child.IsDirty to be true. However, this does not happen. If I update parent.Name then parent.IsDirty is true.
What am I doing wrong? Sample project code is below.
FYI: I've tried removing PropertyChanged.Fody attribute and replacing the properties with Catels property implementation with the same result:
public string Name
{
get { return GetValue<string>(NameProperty); }
set { SetValue(NameProperty, value); }
}
public static readonly PropertyData NameProperty = RegisterProperty("Name", typeof(string), includeInBackup: false);
Sample Code:
using Catel.Data;
/*
* Packages:
* Catel.MVVM (5.10.0)
* PropertyChanged.Fody (4.1.0)
*/
namespace ConsoleApp1
{
/// <summary>
/// Base model with clear dirty function.
/// </summary>
[PropertyChanged.AddINotifyPropertyChangedInterface]
public class ModelBase : ChildAwareModelBase
{
public void ClearDirtyFlag()
{
IsDirty = false;
}
}
/// <summary>
/// Parent object with 1 child and name property.
/// </summary>
[PropertyChanged.AddINotifyPropertyChangedInterface]
class Parent : ModelBase
{
public string Name { get; set; }
public Child Child { get; set; }
}
/// <summary>
/// First child of the parent.
/// </summary>
[PropertyChanged.AddINotifyPropertyChangedInterface]
class Child : ModelBase
{
public string Name { get; set; }
public GrandChild GrandChildOfParent { get; set; }
}
/// <summary>
/// Grand child of the parent.
/// </summary>
[PropertyChanged.AddINotifyPropertyChangedInterface]
class GrandChild : ModelBase
{
public string Name { get; set; }
}
internal class Program
{
static void Main(string[] args)
{
var parent = new Parent();
var child = new Child();
var grandChild = new GrandChild();
parent.Child = child;
child.GrandChildOfParent = grandChild;
parent.ClearDirtyFlag();
child.ClearDirtyFlag();
grandChild.ClearDirtyFlag();
var dirtyCheckParent0 = parent.IsDirty;
child.Name = "dfd";
var dirtyCheckParent1 = parent.IsDirty;
parent.Name = "dfd";
var dirtyCheckParent2 = parent.IsDirty;
Console.ReadLine();
}
}
}