![mybase desktop mybase desktop](http://pic.greenxf.com/Soft/UploadPic/Upload/Fl201812110858195591.png)
The next step is to create logic for the CanExecuteChanged handler. Private Sub AddCommand(ByVal oldCommand As ICommand, ByVal newCommand As ICommand)ĭim handler As New EventHandler(AddressOf CanExecuteChanged)ĪddHandler newCommand.CanExecuteChanged, canExecuteChangedHandler RemoveHandler oldCommand.CanExecuteChanged, handler Private Sub RemoveCommand(ByVal oldCommand As ICommand, ByVal newCommand As ICommand)ĭim handler As EventHandler = AddressOf CanExecuteChanged ' Remove an old command from the Command Property. ' If oldCommand is not null, then we need to remove the handlers. Private Sub HookUpCommand(ByVal oldCommand As ICommand, ByVal newCommand As ICommand) ' Add a new command to the Command Property. NewCommand.CanExecuteChanged += canExecuteChangedHandler Private void AddCommand(ICommand oldCommand, ICommand newCommand)ĮventHandler handler = new EventHandler(CanExecuteChanged) Private void RemoveCommand(ICommand oldCommand, ICommand newCommand)ĮventHandler handler = CanExecuteChanged Remove an old command from the Command Property. If oldCommand is not null, then we need to remove the handlers. Private void HookUpCommand(ICommand oldCommand, ICommand newCommand) Add a new command to the Command Property. The Command property cannot simply be overwritten when a new command is added, because the event handlers associated with the previous command, if there was one, must be removed first. The next step is to add and remove the command which is associated with the command source. Private Shared Sub CommandChanged(ByVal d As DependencyObject, ByVal e As DependencyPropert圜hangedEventArgs)ĭim cs As CommandSlider = CType(d, CommandSlider)Ĭs.HookUpCommand(CType(e.OldValue, ICommand), CType(e.NewValue, ICommand))
![mybase desktop mybase desktop](http://www.aiphere.com/wp-content/uploads/2015/11/111-1024x550.png)
' Command dependency property change callback. Private static void CommandChanged(DependencyObject d,Ĭs.HookUpCommand((ICommand)e.OldValue,(ICommand)e.NewValue) The following is the DependencyProperty change callback: // Command dependency property change callback. Return CType(GetValue(CommandProperty), ICommand) Public ReadOnly Property Command1() As ICommand Implements ICommandSource.Command
![mybase desktop mybase desktop](https://bitsdujourblob.blob.core.windows.net/software/extra/mybase-desktop.png)
![mybase desktop mybase desktop](https://windows-cdn.softpedia.com/screenshots/myBase-Desktop-Edition_12.png)
New Propert圜hangedCallback(AddressOf CommandChanged))) New PropertyMetadata(CType(Nothing, ICommand), Public Shared ReadOnly CommandProperty As DependencyProperty =ĭependencyProperty.Register("Command", GetType(ICommand), ' Make Command a dependency property so it can use databinding. Return (ICommand)GetValue(CommandProperty) New Propert圜hangedCallback(CommandChanged))) Public static readonly DependencyProperty CommandProperty = Make Command a dependency property so it can use databinding. For more information about data binding, see the Data Binding Overview. For more information about the DependencyProperty class, see the Dependency Properties Overview. This enables the properties to use data binding. In this example, the properties are implemented as DependencyProperty objects. The next step is to implement the ICommandSource members. The following is the class definition: public class CommandSlider : Slider, ICommandSource In this example, you'll invoke the command when the slider is moved, or more accurately, when the Value property is changed. These classes invoke a command when they're clicked and they only become a command source when their Command property is set. A command source defines how it invokes a command. WPF provides a number of classes which implement ICommandSource, such as Button, MenuItem, and Hyperlink. In this example, a class is created that inherits from the Slider control and implements the ICommandSource interface. CommandTarget: the object that the command is being executed on.CommandParameter: a user-defined data type which is passed from the command source to the method that handles the command.Command: the command that will be invoked.The ICommandSource interface exposes three members:
#MYBASE DESKTOP HOW TO#
A command source is an object that knows how to invoke a command. This example shows how to create a command source by implementing ICommandSource.