This should be an easy one, but I can't figure it out. When some property of my custom activity changes (e.g. via changing it in the properties grid in WF designer), I want to update the DisplayName dynamically. I do that in the property setter code:
public sealed class TarpSpecItem : Activity, ITarpSpecItem, INotifyPropertyChanged
{
...
public DocumentationType Type
{
get { return _type; }
set { _type = value;
DisplayName = "<" + value.ToString() + ">";
OnPropertyChanged("DisplayName");
OnPropertyChanged("Type");
}
}
The activity implements INotifyPropertyChanged. Yet, the DisplayName does not change on the designer surface. What am I missing?
Will's answer is correct. I'm pasting the updated code of the designer *.xaml.cs here as a separate answer to have correct formatting (not possible as a comment). This code copmpiles and does the trick.
protected override void OnModelItemChanged(object newItem)
{
ModelItem modelItem = newItem as ModelItem;
if (modelItem != null)
modelItem.PropertyChanged += this.ModelItemPropertyChangedHandler;
base.OnModelItemChanged(newItem);
}
private void ModelItemPropertyChangedHandler(object sender, PropertyChangedEventArgs e)
{
if (!e.PropertyName.Equals("Type", StringComparison.OrdinalIgnoreCase))
return;
ModelItem.Properties["DisplayName"].SetValue("<" + ModelItem.Properties["Type"].Value +">");
}
This wrapping of the activity inside the modelitem does not make the solution obvious, does it? It's a bit hard to see what's going on, but it really works. Great job, Will!