For example:
in XAML:
<Page xmlns:local="clr-namespace:MySolution" ....>
<Page.CommandBindings>
<CommandBinding Command="{x:Static local:MyNameSpace.MyClass.MyRCmd}"
Executed="MyCmdBinding_Executed"
CanExecute="MyCmdBinding_CanExecute"/>
</Page.CommandBindings>
...
<Button Command="{x:Static local:MyNameSpace.MyClass.MyRCmd}" ... />
...
</Page>
And in page code behind:
namespace MyNameSpace
{
public partial class MyClass : Page
{
...
public static RoutedCommand MyRCmd = new RoutedCommand();
public event EventHandler CanExecuteChanged;
private void CanExecuteChanged(object sender, EventArgs e)
{
// Here is my problem: How to say to execute this when CanExecute value is
// changing? I would like to execute this on CanExecute value changed.
// I think somewhere I can tell compiler the handler for CanExecutedChanged is
// this. How to?
}
private void MyCmdBinding_Executed(object sender, ExecutedRoutedEventArgs e)
{
// Do my stuff when CanExecute is true
}
private void MyCmdBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (....)
{
e.CanExecute = true;
}
else
{
e.CanExecute = false;
}
}
...
} // end class
} // end namespace
and my problem is how to say compiler: Hey, on CanExecute value changed you must call and do the stuff into CanExecuteChanged method.
Thanks very much.