This project has moved and is read-only. For the latest updates, please go here.

Understanding that Model is being changed when its Shape is already displayed

Mar 20, 2013 at 1:28 PM
Hi,

In my app, changing one certain property of a Model may affect other properties of the same Model - but only when the corresponding Shape is already displayed (and so when changes are initiated by user). If the property is being changed in the process of the Model's deserialization (from my custom Store) - and this happens before Diagram is attached to the Display - it should NOT affect other properties. To implement this, I'm using the following code:

In the MyBaseModel class:
/// <summary>
/// Returns true if the attached shape's Diagram has already acquired a Display component (and so any Model changes are NOT a result of deserialization).
/// </summary>
protected bool IsDisplayed
{
    get { return this.ShapeCount == 1 && this.Shapes.First().Diagram != null && this.Shapes.First().Diagram.DisplayService != null; }
}
In its descendants:
private MyType _myProperty = new MyType();

[PropertyMappingId(MyProperty_PropertyId)]
public MyType MyProperty
{
    get { return _myProperty; }
    set
    {
        if (_myProperty != value)
        {
            _myProperty = value;
            if (this.IsDisplayed)
            {
                // MyProperty was changed BY USER --> update dependent properties:
                // (IMPORTANT: must not happen when changed in the process of deserialization!)
                this.AnotherMyProperty1 = _myProperty.<...>;
                this.AnotherMyProperty2 = _myProperty.<...>;
                // ...
            }
            OnPropertyChanged(MyProperty_PropertyId);
        }
    }
}
Is the code of the IsDisplayed property correct?
Mar 20, 2013 at 2:25 PM
As far as I can see: I think so.