Intersoft ClientUI Documentation
DelegateCommand Class
Members  See Also  Send Feedback
Intersoft.Client.Framework.Input Namespace : DelegateCommand Class






Defines a command that implements ICommand which passes CanExecute and Executed as delegated method. The DelegateCommand is commonly used in M-V-VM pattern application development.

Object Model

DelegateCommand Class

Syntax

Visual Basic (Declaration) 
Public Class DelegateCommand 
Visual Basic (Usage)Copy Code
Dim instance As DelegateCommand
C# 
public class DelegateCommand 
Delphi 
public class DelegateCommand 
JScript 
public class DelegateCommand 
Managed Extensions for C++ 
public __gc class DelegateCommand 
C++/CLI 
public ref class DelegateCommand 

Remarks

ClientUI is sophisticatedly engineered to address a number of challenges in building MVVM pattern applications that target both Silverlight and WPF platform.

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.

Inheritance Hierarchy

System.Object
   Intersoft.Client.Framework.Input.DelegateCommand

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2012 All Rights Reserved.