Dec 4, 2012 at 6:56 PM
Edited Dec 4, 2012 at 6:58 PM
|
The solution I mentioned above was temporary and inelegant. The solution I eventually settled on involves patching BindableApplicationBar's button and menu item classes wherever this.IsEnabled is set to the result of someCommand.CanExecute. For example,
in BindableApplicationBarButton.CommandCanExecuteChanged, I modified the code as follows:
private void CommandCanExecuteChanged(object sender, EventArgs e)
{
if (this.Command != null)
{
var policy = this.Command as IBindableApplicationBarCommand;
if (policy == null || policy.ShallSetIsEnabled)
{
this.IsEnabled = this.Command.CanExecute(this.CommandParameter);
}
}
}
where IBindableApplicationBarCommand is an interface that provides "policy" for the button. Note that this modification is backward compatible; in the absence of policy, the old behavior remains in place.
I did submit a patch for the work item, but it has disappeared from CodePlex. And I no longer have access to the source code for the patch. Nevertheless, the necessary patches are straightforward. Here is the declaration
for IBindableApplicationBarCommand:
namespace BindableApplicationBar
{
/// <summary>
/// Defines a command with policy relevant to the items of a BindableApplicationBar.
/// </summary>
public interface IBindableApplicationBarCommand : ICommand
{
/// <summary>
/// Gets a value indicating whether the IsEnabled property of a button/menu item
/// shall be overwritten by the result of the CanExecute method.
/// </summary>
bool ShallSetIsEnabled { get; }
}
}
Patch the BAB code as outlined above, then assign the Command property of your buttons and menu items to instances of a class that implements this interface, and you should be good to go.
|