views:

27

answers:

1

A quick question on binding to a command in WPF. I've got a command that expects a Boolean as the parameter to execute, but I don't know how to specify the type in the xaml, anyone give me any pointers?

Command Code

public override void Execute(object parameter)
{
   Boolean saveAs = (Boolean)parameter;
}

Xaml Code

<MenuItem Header="Save" Command="{Binding SaveOverlayCommand}" CommandParameter="False">
   <MenuItem.Icon>
      <Image Source="..\resources\save.png" MaxHeight="16" MaxWidth="16"/>
   </MenuItem.Icon>
</MenuItem>
+3  A: 
<MenuItem Header="Save" Command="{Binding SaveOverlayCommand}">
   <MenuItem.CommandParameter>
       <System:Boolean xmlns:System="clr-namespace:System;assembly=mscorlib">False</System:Boolean>
   </MenuItem.CommandParameter>
   <MenuItem.Icon> 
      <Image Source="..\resources\save.png" MaxHeight="16" MaxWidth="16"/> 
   </MenuItem.Icon> 
</MenuItem>
codekaizen
Do I need something additional in my namespacing too? I get an error :''System' is an undeclared prefix. Line 36, position 26.' XML is not valid.
Ian
Yes, you do: `xmlns:System="clr-namespace:System;assembly=mscorlib"`
Dan Puzey
The xmlns should be in the example, if you look carefully.
codekaizen
Hmm, strange. Sure I copied and pasted it... Ah well. Thank you :)
Ian