My ActionMessage parameters aren't being updated

Oct 19, 2010 at 7:01 AM


I am trying to port some code to caliburn micro and I'm running into an issue with Command parameters not being updated automatically.

I have a view with a button that is bound to a command which depends on the SelectedItems property of a datagrid. The xaml for the button is as follows.

<Button Content="Delete" Command="{Binding Path=DeleteLayoutElementTypeCommand}" CommandParameter="{Binding ElementName=dataGridLayoutElementTypes, Path=SelectedItems}" />

The above command is implemented as an ICommand with the following CanExecute method

private bool CanDeleteLayoutElementType(IList layoutElementTypesToDelete)
     if (layoutElementTypesToDelete == null)
          return false;

     return layoutElementTypesToDelete.Count > 0;

The expected behaviour is for the button to become enabled when one or more items are selected on the datagrid.

My question is how do I get the above to work in Caliburn Micro?

Using the available articles I came up with the following xaml

<Button Content="Delete" >
         <i:EventTrigger EventName="Click">
             <cal:ActionMessage MethodName="DeleteLayoutElementType">
                 <cal:Parameter Value="{Binding ElementName=dataGridLayoutElementTypes, Path=SelectedItems}" />

My button is always in a disabled state due to the datagrid not having any selected items on startup. Changes in the datagrid selection are however not causing the CanExecute method to be re-evaluated.

Any suggestions would be welcome.



Oct 19, 2010 at 9:53 AM

Thanks, I solved my problem letting by the ViewModel do the work.

I used the approach of listening to the SelectionChanged event on the DataGrid and using it to set a selectedItemsCollection on the ViewModel via a command.