C# 在Windows工作流自定义活动中使用ICommand

C# 在Windows工作流自定义活动中使用ICommand,c#,xaml,workflow-foundation-4,workflow-foundation,C#,Xaml,Workflow Foundation 4,Workflow Foundation,我在WPF项目中使用了很多中继命令,但我目前正在处理Windows工作流,并且正在使用自己的设计器进行自定义活动。我想在我的设计按钮,以添加新的领域,如果按下。我花了好几天的时间在互联网上搜索,但似乎windows工作流已经击败了我。这是我所拥有的,它不起作用,如果有人知道为什么,请帮助 [Designer(typeof(MyCustomActivityDesigner))] public sealed class MyCustomActivity : AsyncCodeActivity {

我在
WPF
项目中使用了很多中继命令,但我目前正在处理Windows工作流,并且正在使用自己的设计器进行自定义活动。我想在我的设计按钮,以添加新的领域,如果按下。我花了好几天的时间在互联网上搜索,但似乎windows工作流已经击败了我。这是我所拥有的,它不起作用,如果有人知道为什么,请帮助

[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
    }
}
中继命令执行:

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;
}
xaml只是一个带有命令绑定的按钮,但由于windows工作流的怪异特性,它会通过ModelItem(至少对于我拥有的其他绑定)


因此,与我在
WPF
应用程序中使用的代码的关键区别在于无参数构造函数,但这不应该影响它吗经过测试,无参数构造函数在WPF应用程序中运行良好,因此这一定是因为ModelItem无法处理命令?

ModelItem绑定路径也适用于viewmodel上的所有其他可绑定属性(例如标签上的字符串)


注意:这些活动在重新注册的设计器中进行了测试/显示。

我想我找到了解决方案,我今天正在运行测试,所以明天可能会发布一个答案,发现有人使用了它,但他没有解释他是如何做到的。。。至少我们知道这是可能的lol
<Button Command="{Binding Path=ModelItem.AddSpecificParameter}"/>