Introduced
Silverlight 4.0 MVVM Mode:
* ICommand-command. It can be bound to the Command property of the ButtonBase or Hyperlink
* MVVM Mode-Model-view-viewmodel
Online Demo
Http://www.cnblogs.com/webabcd/archive/2010/08/09/1795417.html
Example
1. Demo ICommand Application
MyCommand.cs
Code
/*
* ICommand-command. It can be bound to the Command property of the ButtonBase or hyperlink
* BOOL CanExecute (object parameter)-when asked if the command can be executed
* Event EventHandler canexecutechanged-Events triggered when the state in which the command can be executed has changed
* void Execute (object parameter)-the method that is invoked when the current command is executed
*/
Using System;
Using System.Net;
Using System.Windows;
Using System.Windows.Controls;
Using System.Windows.Documents;
Using System.Windows.Ink;
Using System.Windows.Input;
Using System.Windows.Media;
Using System.Windows.Media.Animation;
Using System.Windows.Shapes;
Namespace Silverlight40.Binding.Command
{
public delegate void Execute (object parameter);
Public delegate bool CanExecute (object parameter);
public class Mycommand:icommand
{
Private Execute _executemethod;
Private CanExecute _canexecutemethod;
Public MyCommand ()
: This (null, NULL)
{
}
Public mycommand (Execute Executemethod)
: This (Executemethod, NULL)
{
}
Public MyCommand (Execute Executemethod, CanExecute Canexecutemethod)
{
_executemethod = Executemethod;
_canexecutemethod = Canexecutemethod;
}
public bool CanExecute (object parameter)
{
if (_canexecutemethod = null)
return true;
Else
return _canexecutemethod (parameter);
}
public void Execute (object parameter)
{
if (_executemethod!= null)
_executemethod (parameter);
}
public event EventHandler Canexecutechanged;
protected virtual void oncanexecutechanged (EventArgs e)
{
if (canexecutechanged!= null)
Canexecutechanged (this, e);
}
public void raisecanexecutechanged ()
{
Oncanexecutechanged (Eventargs.empty);
}
}
}