Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send a boolean as an Action parameter in Caliburn Micro

This is my XAML View (some code omitted for readability):

<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>
And here's the code in the ViewModel:
public void Close(bool save) 
{
  if (save) 
  { 
    // save the data 
  }
  TryClose();
}
This doesn't work - of course - because the action parameters "true" and "false" aren't objects or object properties in the XAML. How can I make this work, and send a boolean as an Action parameter in Caliburn Micro?
like image 278
KBoek Avatar asked Nov 07 '11 10:11

KBoek


1 Answers

If you put single quotes around the parameter name, it will properly convert for you.

<Button Content="Close without saving"
        c:Message.Attach="Close('false')" />
<Button Content="Save and Close"
        c:Message.Attach="Close('true')" />
like image 71
Adrian Avatar answered Oct 09 '22 08:10

Adrian