Joh*_*ris 5 c# xaml workflow-foundation workflow-foundation-4
我在WPF
项目中使用了Relay Commands,但我目前正在使用Windows Workflows,而我正在使用自己的设计器进行自定义活动.如果按下,我想在我的设计上添加一个按钮来添加新字段.我花了几天时间在互联网上搜索,但似乎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
}
}
Run Code Online (Sandbox Code Playgroud)
中继命令实现:
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;
}
Run Code Online (Sandbox Code Playgroud)
xaml只是一个带有命令绑定的按钮,但由于Windows工作流程奇怪的东西,它通过ModelItem(至少对于我有的其他绑定)
<Button Command="{Binding Path=ModelItem.AddSpecificParameter}"/>
Run Code Online (Sandbox Code Playgroud)
因此,我在WPF
应用程序中运行的代码的主要区别是无参数构造函数,但这不应该影响它吗?经过测试,无参数构造函数在WPF应用程序中运行良好,因此必须归因于ModelItem无法处理命令?
此外,ModelItem绑定路径适用于viewmodel上的所有其他可绑定属性(例如标签上的字符串)
注意:活动在重新托管的设计器中进行测试/显示.
归档时间: |
|
查看次数: |
135 次 |
最近记录: |