What should you do?

You use Microsoft .NET Framework to create a Windows Presentation Foundation (WPF) application. You create a window that contains a Button control and a MenuItem control. Both controls are labeled “Add sugar.” The Command properties of the Button and MenuItem controls are set to the same RoutedCommand named AddSugarCommand. You write the following code segment.

Private Sub CanAddSugar(sender As Object, e As CanExecuteRoutedEventArgs) …
End Sub

You need to ensure that when the CanAddSugar method sets e.CanExecute to false, the MenuItem and Button controls are disabled. What should you do?

You use Microsoft .NET Framework to create a Windows Presentation Foundation (WPF) application. You create a window that contains a Button control and a MenuItem control. Both controls are labeled “Add sugar.” The Command properties of the Button and MenuItem controls are set to the same RoutedCommand named AddSugarCommand. You write the following code segment.

Private Sub CanAddSugar(sender As Object, e As CanExecuteRoutedEventArgs) …
End Sub

You need to ensure that when the CanAddSugar method sets e.CanExecute to false, the MenuItem and Button controls are disabled. What should you do?

A.
Create an event handler for the CanExecuteChanged event of the AddSugarCommand command. Call the CanAddSugar method from within the event handler.

B.
Inherit the AddSugarCommand from the RoutedUICommand class instead of the RoutedCommand class. Call the CanAddSugar method from within the constructor of the AddSugarCommand command.

C.
Add a CommandBinding object to the CommandBinding property of the MenuItem control.
Set the CanExecute property of the CommandBinding object to the CanAddSugar method.

D.
Add a CommandBinding object to the CommandBindings property of the window. Set the Command property of CommandBinding to the AddSugarCommand command. Set the CanExecute property of the CommandBinding object to the CanAddSugar method.



Leave a Reply 0

Your email address will not be published. Required fields are marked *