我有一个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);
}
}
}
问题是
RelayCommand
类型未知,我不知道程序集缺少什么。谢谢,
最佳答案
RelayCommand是由MS创建的用于在WPF中处理事件或命令的类。您可以创建自己的类(class)或通过下面的链接。
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
关于c# - 找不到RelayCommand的引用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21405792/