RelayCommand's reference is not found

Lamloumi Afif picture Lamloumi Afif · Jan 28, 2014 · Viewed 11.4k times · Source

I have a WPF application in which i'd like to change its design pattern to MVVM.I have used this snippet

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

  }
}

The problem is that the RelayCommand type is not known and i don't know what is the assembly missing.

  • So how can i fix this problem?

Thanks,

Answer

J R B picture J R B · Jan 28, 2014

RelayCommand is a class created by MS for handling event or command in WPF. you can create own class or go through below link.

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