Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Using ICommand in Windows Workflow Custom Activities

$
0
0
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)

Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>