title: Relay command in Wpf
body: <p>I'm new to c# and trying to understand how commands work in mvvm architecture. What I need to do is that updating some info when I click a button. I think I implemented the relay class fine but there is no update at all.</p>
  
  <p><strong>RelayCommand.cs</strong></p>
  
  <pre><code>public class RelayCommand : ICommand
  {
      private Action&lt;object&gt; execute;
      private Func&lt;object, bool&gt; canExecute;
  
      public event EventHandler CanExecuteChanged
      {
          add { CommandManager.RequerySuggested += value; }
          remove { CommandManager.RequerySuggested -= value; }
      }
  
      public RelayCommand(Action&lt;object&gt; execute, Func&lt;object, bool&gt; canExecute)
      {
          this.execute = execute;
          this.canExecute = canExecute;
      }
  
      public bool CanExecute(object parameter)
      {
          return this.canExecute == null || this.canExecute(parameter);
      }
  
      public void Execute(object parameter)
      {
          this.execute(parameter);
      }
  }
  </code></pre>
  
  <p><strong>MovieViewModel.cs</strong></p>
  
  <pre><code>class MovieViewModel : INotifyPropertyChanged
  {
      Movie _movie;
  
      private ICommand _updateCommand;
      public event PropertyChangedEventHandler PropertyChanged;
  
      public MovieViewModel()
      {
          _movie = new Movie
          {
              Title = "Unknown",
              Genre = "Unknown",
              Price = 11.0,
              Score = 0
          };
      }
  
      public Movie Movie
      {
          get
          {
              return _movie;
          }
          set
          {
              _movie = value;
          }
      }
  
      public string Title
      {
          get
          {
              return Movie.Title;
          }
          set
          {
              Movie.Title = value;
              RaisePropertyChanged("Title");
          }
      }
  
      public string Genre
      {
          get
          {
              return Movie.Genre;
          }
          set
          {
              Movie.Genre = value;
              RaisePropertyChanged("Genre");
          }
      }
  
      public double Price
      {
          get
          {
              return Movie.Price;
          }
          set
          {
              Movie.Price = value;
              RaisePropertyChanged("Price");
          }
      }
  
      public double Score
      {
          get
          {
              return Movie.Score;
          }
          set
          {
              Movie.Score = value;
              RaisePropertyChanged("Score");
          }
      }
  
      private void RaisePropertyChanged(string name)
      {
        PropertyChanged(this, new PropertyChangedEventArgs(name));
      }
  
      public ICommand UpdateCommand
      {
          get
          {
              if (_updateCommand == null)
              {
                  _updateCommand = new RelayCommand(p =&gt; { updateMovie("ASD", "ZXC", 11.90, 0); }, p =&gt; true);
              }
              return _updateCommand;
          }
          set
          {
              _updateCommand = value;
          }
      }
  
      public Movie updateMovie(string title, string genre, double price, double score)
      {
          _movie.Title = title;
          _movie.Genre = genre;
          _movie.Price = price;
          _movie.Score = score;
  
          return _movie;
      }
  }
  </code></pre>
  
  <p><strong>Button command binding</strong></p>
  
  <pre><code>&lt;Button x:Name="updateBtn" Content="Update" Grid.Column="1" Grid.Row="5" Width="75" Height="30" Command="{Binding UpdateCommand}"/&gt;
  </code></pre>