Slow and steady Silverlight (52)

Source: Internet
Author: User
Tags bool silverlight

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);
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.