找不到RelayCommand的参考

Lam*_*fif 5 c# wpf command mvvm relaycommand

我有一个WPF应用程序,我想将其设计模式更改为MVVM.我已使用此代码段

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FirstMVVm.Model;
using System.ComponentModel;
using System.Windows.Input;
using System.Windows;
namespace FirstMVVm.ModelView
{
    class MyViewModel: INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private float result;

          public float Result
          {
           get { return result; }
              private set
              {
                  if (result != value) { 
                      result = value;
                  if (PropertyChanged != null)
                  {
                      PropertyChanged(this, new PropertyChangedEventArgs("Result"));
                  }
                     }
                    }
                 }

          public int Number { get; set; }

        private RelayCommand _calculatePerimeterCommand;

        public ICommand CalculatePerimeterCommand
                  {
                  get
                    {
                    if (_calculatePerimeterCommand == null)
                      {
                          _calculatePerimeterCommand = new RelayCommand(param => this.CalculatePerimeter());
                       }
                    return _calculatePerimeterCommand;
                       }
                      }
        private MyModel _model;

        public MyViewModel() {
            _model = new MyModel();
        }


        private void CalculatePerimeter(){
            Result = _model.Perimetre(Number);
        }

  }
}
Run Code Online (Sandbox Code Playgroud)

问题是该RelayCommand 类型未知,我不知道组件丢失的是什么.

  • 那么我该如何解决这个问题呢?

谢谢,

J R*_*R B 8

RelayCommand是MS创建的用于处理WPF中的事件或命令的类.你可以创建自己的类或通过以下链接.

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx