Intersoft.Client.Framework.Input Namespace : DelegateCommand Class |
Public Class DelegateCommand
Dim instance As DelegateCommand
public class DelegateCommand
public ref class DelegateCommand
ClientUI streamlines the application development using MVVM pattern with commanding pattern which has been extended to work in both platforms. One of the techniques used in ClientUI is by extending the commanding framework to support MVVM through built-in DelegateCommand class.
Built on the top of ClientUI commanding framework, the DelegateCommand enables you to define the commands and its logic in a ViewModel class and bind to them in the View through the Command property. Furthermore, the DelegateCommand takes advantage of the routed command concept in which the IsEnabled state of the command sources will be automatically synchronized depending on whether the command can execute.
This example shows how to create DelegateCommand in the ViewModel and bind it to the Command property of the UXToolBarButton in the View.
XAML |
Copy Code
|
---|---|
<Intersoft:UXPage.Resources> <ViewModels:EditorViewModel x:Key="EditorViewModel"></ViewModels:EditorViewModel> </Intersoft:UXPage.Resources> <Grid x:Name="LayoutRoot" DataContext="{StaticResource EditorViewModel}"> <Intersoft:UXToolBar HorizontalAlignment="Left" Margin="10,10,0,0" Name="uXToolBar1" VerticalAlignment="Top"> <Intersoft:UXToolGroup> <Intersoft:UXToolBarButton Content="New" Command="{Binding NewAction}"/> </Intersoft:UXToolGroup> </Intersoft:UXToolBar> </Grid> |
C# |
Copy Code
|
---|---|
public class EditorViewModel : ViewModelBase { public EditorViewModel() { this.NewAction = new DelegateCommand(NewCommandAction, CanNewAction); } public DelegateCommand NewAction { get; private set; } private bool CanNewAction(object parameter) { //this method validate whether or not the New ToolBarButton is active //In this sample, I will keep the New ToolBarButton to be always active return true; } private void NewCommandAction(object parameter) { //this method will be triggered when the New ToolBarButton is clicked MessageBoxServiceProvider.Standalone = true; MessageBoxServiceProvider.Show("Execute New Action", "Information", Intersoft.Client.UI.Aqua.UXDesktop.MessageBoxButton.OK, Intersoft.Client.UI.Aqua.UXDesktop.MessageBoxImage.Information, null); } } |
For a more complete version of this example, see How-to: Handle Tool Bar Command using MVVM Pattern.
To learn more about using MVVM pattern in ClientUI application development, see Walkthrough: Create Your First ClientUI Application using MVVM Pattern.System.Object
Intersoft.Client.Framework.Input.DelegateCommand
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2