在Caliburn Micro中将布尔值作为Action参数发送

KBo*_*oek 13 xaml .net-4.0 caliburn.micro c#-4.0

这是我的XAML视图(为了便于阅读,省略了一些代码):

<Window ... xmlns:c="http://www.caliburnproject.org">
  <Button Content="Close without saving" c:Message.Attach="Close(false)" />
  <Button Content="Save and Close" c:Message.Attach="Close(true)" />
</Window>
Run Code Online (Sandbox Code Playgroud)这是ViewModel中的代码:
public void Close(bool save) 
{
  if (save) 
  { 
    // save the data 
  }
  TryClose();
}
Run Code Online (Sandbox Code Playgroud)这当然不起作用 - 因为动作参数"true"和"false"不是XAML中的对象或对象属性.如何使这项工作,并在Caliburn Micro中将一个布尔值作为Action参数发送?

Adr*_*ian 23

如果在参数名称周围加上单引号,它将为您正确转换.

<Button Content="Close without saving"
        c:Message.Attach="Close('false')" />
<Button Content="Save and Close"
        c:Message.Attach="Close('true')" />
Run Code Online (Sandbox Code Playgroud)