Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Windows. input;
Namespace SC
{
/// <Summary>
/// Delegate command for view Model
/// </Summary>
Public class delegatecommand: icommand
{
# Region members
/// <Summary>
/// Can execute function
/// </Summary>
Private readonly func <bool> canexecute;
/// <Summary>
/// Execute function
/// </Summary>
Private readonly action execute;
# Endregion
/// <Summary>
/// Initializes a new instance of the delegatecommand class.
/// </Summary>
/// <Param name = "execute"> indicate an execute function </param>
Public delegatecommand (Action execute)
: This (execute, null)
{
}
/// <Summary>
/// Initializes a new instance of the delegatecommand class.
/// </Summary>
/// <Param name = "execute"> Execute function </param>
/// <Param name = "canexecute"> can execute function </param>
Public delegatecommand (Action execute, func <bool> canexecute)
{
This.exe cute = execute;
This. canexecute = canexecute;
}
/// <Summary>
/// Can executes event handler
/// </Summary>
Public event eventhandler canexecutechanged
{
Add {commandmanager. requerysuggested + = value ;}
Remove {commandmanager. requerysuggested-= value ;}
}
/// <Summary>
/// Implement of icommand can execute Method
/// </Summary>
/// <Param name = "parameter"> parameter by default of icomand interface </param>
/// <Returns> can execute or not </returns>
Public bool canexecute (object parameter)
{
If (this. canexecute = NULL)
{
Return true;
}
Return this. canexecute ();
}
/// <Summary>
/// Implement of icommand interface execute Method
/// </Summary>
/// <Param name = "parameter"> parameter by default of icomand interface </param>
Public void execute (object parameter)
{
This.exe cute ();
}
}
/// <Summary>
/// Delegate command for view Model
/// </Summary>
Public class delegatecommand <t>: icommand
{
# Region members
/// <Summary>
/// Can execute function
/// </Summary>
Private readonly func <t, bool> canexecute;
/// <Summary>
/// Execute function
/// </Summary>
Private readonly action <t> execute;
# Endregion
/// <Summary>
/// Initializes a new instance of the delegatecommand class.
/// </Summary>
/// <Param name = "execute"> indicate an execute function </param>
Public delegatecommand (Action <t> execute)
: This (execute, null)
{
}
/// <Summary>
/// Initializes a new instance of the delegatecommand class.
/// </Summary>
/// <Param name = "execute"> Execute function </param>
/// <Param name = "canexecute"> can execute function </param>
Public delegatecommand (Action <t> execute, func <t, bool> canexecute)
{
This.exe cute = execute;
This. canexecute = canexecute;
}
/// <Summary>
/// Can executes event handler
/// </Summary>
Public event eventhandler canexecutechanged
{
Add {commandmanager. requerysuggested + = value ;}
Remove {commandmanager. requerysuggested-= value ;}
}
/// <Summary>
/// Implement of icommand can execute Method
/// </Summary>
/// <Param name = "parameter"> parameter by default of icomand interface </param>
/// <Returns> can execute or not </returns>
Public bool canexecute (object parameter)
{
If (this. canexecute = NULL)
{
Return true;
}
Return this. canexecute (t) parameter );
}
/// <Summary>
/// Implement of icommand interface execute Method
/// </Summary>
/// <Param name = "parameter"> parameter by default of icomand interface </param>
Public void execute (object parameter)
{
This.exe cute (t) parameter );
}
}
}
Delegatecommand. CS