Hi
I'm using NetAdvantage_Silverlight_2010 Vol.3
i'm trying to bind ButtonTool.Commands to my command, This command binding work correct and command CanExecute and Execute work perfect but result of CanExecute method not effect on ButtonTool to Enable or disabling it.
what is problem?
Thanks
Hi,
In order for the control to be disabled or enabled, you need to notify the Commanding Framework that CanExecute has changed for your custom command, so the associated controls can then call the CanExecute() method off the CommandSource and update their IsEnabled state accordingly.
In order to do that, you'll need to call a static method of the CommandSourceManager class:
CommandSourceManager.NotifyCanExecuteChanged(typeof(MyCustomCommand));
I've attached a sample that demostrates that. In the attached sample, the static method is called in the setter of CanExecuteCommandFlag, so when the value of the flag changes, the ButtonTool can automatically update its state.
Hope that helps,
Thanks Georgi
But in SampleApp1 project there is still a Bug that i can't figur out how to resolve it,
if we change CanExecuteCommandFlag to flase like this :
public TestData() { this.CanExecuteCommandFlag = false; }
At Start Time of Application, Btn1 should be in Disbale state, but this not work. can you say me what is problem ?
I've already created a bug item about this. My guess is that there's some timing issue with the Controls for ribbon's tools being generated after the "NotifyCanExecuteChanged" was already called. As a workaround you can add the following code to the Loaded event of the UserControl:
void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
this.Dispatcher.BeginInvoke(() =>
CommandSourceManager.NotifyCanExecuteChanged(typeof(MyCommand));
});
}