none
Using ICommand in Windows Workflow Custom Activities RRS feed

  • Question

  • I have used Relay Commands quite a bit in WPF projects but I am currently working on Windows Workflows and I am making a custom activity with its own designer. I want a button on my design to add new fields if pressed. I have spent days trawling the internet but it seems windows workflow has defeated me. This is what I have and it does not work, if anyone knows why please help.

        [Designer(typeof(MyCustomActivityDesigner))]
        public sealed class MyCustomActivity : AsyncCodeActivity
            {
                public MyCustomActivity()
                {
                    AddSpecificParameter = new DelegateCommand(AddParameter);
                }
                public DelegateCommand AddSpecificParameter { get; set; }
       
                public void AddParameter()
                {
        //add value to an obervable collection
                }
        }


    Relay command implementation:

      public class DelegateCommand :ICommand
          {
            //Parameterless constructor needed as windows workflow serialises it
            public DelegateCommand()
            { }

            private readonly Action _action;

            public DelegateCommand(Action action)
            {
                _action = action;
            }
            public void Execute(object parameter)
            {
                _action();
            }
            public bool CanExecute(object parameter)
            {
                return true;
            }

            public event EventHandler CanExecuteChanged;
        }

    And the xaml is simply a button with a command binding but due to windows workflow weird stuff it goes through ModelItem (at least for the other bindings I have)

        <Button Command="{Binding Path=ModelItem.AddSpecificParameter}"/>

    So the key differences from code that I have in WPF apps that works is the parameterless constructor but this shouldnt effect it? 

    Also the ModelItem Binding path works for all the other bindable properties on the viewmodel (strings for lables)
    Friday, September 28, 2018 11:47 AM

All replies

  • Hi JohnChrisGreek,

    According to your description, you want to use Icommand in Window Workflow Custom Activities, but this forum is discussing question about wpf developing, so you can ask your question for Window Workflow foundation forum for professional help.

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 1, 2018 2:43 AM
  • Hi,

    Thank you, I didnt notice I did that, Ill post my question in the correct place.

    Tuesday, October 2, 2018 7:07 AM