|
I'm trying to use the DelegateCommand class to control what commands are available on each element of a DataGrid control. My application is based on the techniques used in the Waf Book Library application, so it should be easy to show an example. To emulate
my problem I modified the Book Library application to try to control whether the LendToCommand is available on each book. To do this I made the following changes to the code in the BookController class:
// Original code: this.lendToCommand = new DelegateCommand(p => LendTo((Book)p));
this.lendToCommand = new DelegateCommand(p => LendTo((Book)p), p => CanLendTo((Book)p));
...and now add the CanLendTo function like so:
// This is a new method added to the ReportController class
private bool CanLendTo(Book book) { return false; }
I see the behavior I expect, which is that the LendToCommand is disabled for *every* book in the BookListViewModel. However, what's causing me issue is that the book parameter passed into the CanLendTo method is always null, so I can't make any meaningful
decisions about the Command for each book. In my actual application I want to control what Commands are available based on the permissions the current user has. Imagine for the book library that some users can lend out books by a specific author, but other
can not. From what I can tell the DelegateCommand class seems to support this, but I'm new to WPF so is there something obvious I'm missing here?
Thanks for any insight anyone can provide.
|