【发布时间】:2014-02-19 18:19:07
【问题描述】:
我有一个 WPF 应用程序,我想将其设计模式更改为 MVVM。我使用了这个 sn-p
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 类型未知,我不知道程序集缺少什么。
- 那么我该如何解决这个问题呢?
谢谢,
【问题讨论】:
-
我只知道 Prism 或 Unity 示例中的 RelayCommand 作为 ICommand 的示例实现。作为组件中的实现,我只知道 Prism 的 delegateCommand。你从哪里得到这个 sn-p?
标签: c# wpf mvvm command relaycommand