Own validation logic of custom Activity RRS feed

  • Question

  • Hello,

    for my rehosted project I have already designed a custom Activity and a custom ActivityDesigner.
    Now I would like to add some own validation logic by making a glyph appear under certain circumstances (controlled by a bool):

    protected override void CacheMetadata(NativeActivityMetadata metadata)
                if (ActivityItems.Count == 0)
                    HasErrors = true;
                    HasErrors = false;

    The XAML looks like this:

    <Image DockPanel.Dock="Right" Source="../expression.png" Margin="2" Height="16" VerticalAlignment="Top" HorizontalAlignment="Right" >
                        <Image.Style >
                            <Style TargetType="{x:Type Image}">
                                <Setter Property="Visibility" Value="Hidden" />
                                    <DataTrigger Binding="{Binding ModelItem.HasErrors}" Value="true">
                                        <Setter Property="Visibility" Value="Visible" />
                                    <DataTrigger Binding="{Binding ModelItem.HasErrors}" Value="false">
                                        <Setter Property="Visibility" Value="Hidden" />

    When there is a change in my workflow, the attribute's value is set correctly but it has no effect on my designer. (Actually on debugging, the value is changed, but remains unchanged in PropertyInspectorView...).

    Just when the sequence is unloaded and loaded again the value has changed and the glyph is visible..
    What am I doing wrong?

    Thank you!

    Tuesday, February 7, 2012 6:54 AM

All replies

  • Use the INotifyPropertyChanged for the HasError bool.
    • Marked as answer by lyndon23 Wednesday, February 8, 2012 7:52 AM
    • Unmarked as answer by lyndon23 Wednesday, February 8, 2012 7:52 AM
    Wednesday, February 8, 2012 3:28 AM
  • Does not work either, the handler in 

    private void OnPropertyChanged(string propertyName)
         PropertyChangedEventHandler handler = PropertyChanged;
         if (handler != null)
               handler(this, new PropertyChangedEventArgs(propertyName));

    is always null.
    When I try to set the value programmatically (HasErrors = true;), the set operation ist not called...

    Wednesday, February 8, 2012 7:59 AM
  • Unfortunately ModelItem doesn't subscribe to INotifyPropertyChanged on the underlying activity object. So you can only get property notification from ModelItem.HasErrors if HasErrors was set using a model item API (ModelProperty.SetValue etc), since ModelItem.HasErrors actually refers to a model property.

    However, in your designer WPF you are not limited to only binding to Modeltem Properties, you should be able to bind directly to your own INotifyPropertyChanged property by e.g.

    a) creating an 'Activity' property on your Designer which returns the wrapped Activity inside the model item.


    b) binding to Activity.HasErrors

    • Proposed as answer by Tim Lovell-Smith Wednesday, February 8, 2012 10:16 PM
    • Unproposed as answer by lyndon23 Monday, February 13, 2012 8:50 AM
    • Proposed as answer by Tim Lovell-Smith Thursday, February 23, 2012 12:23 PM
    • Unproposed as answer by lyndon23 Saturday, March 3, 2012 8:50 PM
    Wednesday, February 8, 2012 5:37 PM
  • I'm not quite sure how to do that, could you provide sample code?

    Thank you

    Thursday, February 9, 2012 6:51 AM
  • a)

    public Activity MyActivity { get { return (Activity)this.ModelItem.GetValue(); } }


    instead of {Binding Path=ModelItem.HasErrors}

    {Binding Path=Activity.HasErrors}

    - you are already implementing IActivityPropertyChanged on your activity right?


    • Proposed as answer by Tim Lovell-Smith Thursday, February 23, 2012 12:23 PM
    • Unproposed as answer by lyndon23 Thursday, February 23, 2012 1:40 PM
    Wednesday, February 15, 2012 12:50 AM
  • Hi,

    sorry for the late reply.

    a) So you mean creating an "Activity" property in the xaml.cs of my Designer where the glyph or whatever shall be shown?

    public Activity MyActivity { get { return (Activity)this.ModelItem.GetValue(); } } 

    There is no method "GetValue" of ModelItem, only "GetCurrentValue", right? Anyway my debugger never stops at this line using GetCurrentValue.

    b) Ok I see, binding to the wrapped Activity.
    Did you mean INotifyPropertyChanged? Well, I'm not implementing it right now as it did not help me in the past.


    Thursday, February 23, 2012 1:39 PM