Your Activity
is wrapped in a ModelItem
, which handles all notification services between the Activity and the design surface.
When initially wrapped within the designer, the ModelItem
does not inspect your Activity
to see if it provides some property change notification method (INPC, a custom TypeDescriptor
, etc) or other interfaces (i.e., IDataErrorInfo
, for which I have a connect here).
So, essentially, you cannot do what you are attempting to accomplish here. From within the Activity, you cannot send change notification back through the wrapping ModelItem. Which you really shouldn't be doing, anyhow.
In the designer, state change should only pass through the ModelItem
, as it needs to keep its state in sync with the wrapped Activity
. If its state and the wrapped instance's state become misaligned, you won't see the correct information in the designer.
// we're doing this in the designer
var activity = ModelItem.GetCurrentValue() as MyActivity;
activity.DisplayName = "You won't ever see this in the design surface!";
Instead, you must make code changes through the ModelItem
// again, in the designer code
ModelItem.Properties["DisplayName"].Value = "You will see this change!";
So, what's the solution? The only real solution is to ensure that your Activities
are passive when their state changes! Property value changes shouldn't trigger anything.
Instead, move code like this into the designer!
override OnModelItemChanged(object obj)
{
// live dangerously!
var mi = obj as ModelItem;
mi.PropertyChanged += OnPropertyChanged;
}
void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if(!e.PropertyName.Equals("Type", StringComparison.OrdinalIgnoreCase))
return;
ModelItem.Properties["DisplayName"].Value =
"<" +
ModelItem.Properties["Type"].GetCurrentValue().ToString() +
">";
}
Of course, you can't just copypaste this. And it might have some bugs. But it gives you an idea what you have to do.