title: Passing Command/Parameter to BackCode?
body: <p>Teaching myself and struggling with what is probably a basic concept. So any additional explanation is welcome... I have the following code which works perfectly from a Button_Click Event and Code Behind. I am ok with using a little Code Behind because it is basically just manipulating the View. However, I want to get the data/business logic from the ViewModel. I am able to confirm (with messagebox.show) that my data is getting passed correctly, however the UI does not update using the new data like it does when data comes from the Button_Click Event. I have been having a difficult time with this for a while and keep finding work arounds. For all I know my approach is totally wrong. I would really like to know how to do this.</p>
  
  <p>WPF</p>
  
  <pre><code>&lt;StackPanel Grid.Row="1"  VerticalAlignment="Bottom"&gt;
  
          &lt;TextBox x:Name="NumberOfDays" HorizontalAlignment="Left" Background="GreenYellow" Foreground="Black"&gt;
  
          &lt;/TextBox&gt;
          &lt;StackPanel Orientation="Horizontal"&gt;
              &lt;Button Content="change hello row" Click="Button_Click" HorizontalAlignment="Left" Background="GreenYellow" Foreground="Black"&gt;
  
              &lt;/Button&gt;
  
              &lt;Button  Content="TestCommand5" Margin="0 0 0 0" Padding="5" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="16"
                       CommandParameter="{Binding objActiveJobClass.JobID}"
                       Command="{Binding TestCommand5}" 
                       IsTabStop = "False" FocusVisualStyle="{DynamicResource MyFocusVisual}"
                       Style="{Binding Mode=OneWay, Source={StaticResource NavigationButtonStyle}}"&gt;
  
              &lt;/Button&gt;
          &lt;/StackPanel&gt;
  
  
          &lt;Label Content="Gant Chart Area" HorizontalAlignment="Left"/&gt;
  
          &lt;ScrollViewer Width="1200"  HorizontalAlignment="Left" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto"&gt;
              &lt;Grid &gt;
                  &lt;Canvas x:Name="GantChartCanvas" HorizontalAlignment="Left" Background="Yellow" Height="405" /&gt;
              &lt;/Grid&gt;
  
          &lt;/ScrollViewer&gt;
  
      &lt;/StackPanel&gt;
  </code></pre>
  
  <p>BackCode:</p>
  
  <pre><code>public partial class GantChartUserControl : UserControl
  {
      public GantChartUserControl()
      {
          InitializeComponent();
      }
  
      public GantChartUserControl(int Duration)
      {
          InitializeComponent();
          CreateTimeLine(Duration);
      }
  
      private void Button_Click(object sender, RoutedEventArgs e)
      {
          int variable = 0;
          if (NumberOfDays != null)
          {
              int.TryParse(NumberOfDays.Text, out variable);
              if (variable &gt; 0)
              {
                  CreateTimeLine(variable);
              }
              else
              {
                  MessageBox.Show($"\"{NumberOfDays.Text}\" is not an INTEGER greater than Zero.");
              }
          }
      }
  
      public void CreateTimeLine(int duration)
      {
          MessageBox.Show($"CreateTimeLine duration {duration}");
  
          GantChartCanvas.Children.Clear();
  
          double ControlWidth = 100d;
          int Duration = duration;
  
          for (int i = 0; i &lt; Duration; i++)
          {
              Label u1 = new Label();
              u1.HorizontalAlignment = HorizontalAlignment.Left;
              u1.VerticalAlignment = VerticalAlignment.Bottom;
              u1.HorizontalContentAlignment = HorizontalAlignment.Center;
              u1.VerticalContentAlignment = VerticalAlignment.Center;
              u1.Background = IsOdd(i) ? Brushes.Gray : Brushes.DarkGray;
  
              u1.Height = 30;
              u1.Width = ControlWidth;
  
              u1.SetValue(Canvas.LeftProperty, (ControlWidth * i));
              u1.SetValue(Canvas.BottomProperty, 0d);
              u1.Content = string.Concat("LABEL ", i + 1);
  
              GantChartCanvas.Width = Duration * ControlWidth;
              GantChartCanvas.Children.Add(u1);
          }         
      }
  
      public static bool IsOdd(int value)
      {
          return value % 2 != 0;
      }       
  }
  </code></pre>
  
  <p>ViewModel</p>
  
  <pre><code>private ICommand _TestCommand5;
      public ICommand TestCommand5
      {
          get
          {
              if (_TestCommand5 == null)
              {
                  _TestCommand5 = new RelayCommand&lt;object&gt;(ExecuteTestCommand5, CanExecuteTestCommand5);
              }
  
              return _TestCommand5;
          }
      }
      public bool CanExecuteTestCommand5(object parameter)
      {
          return true;
      }
      public void ExecuteTestCommand5(object parameter)
      {
          Debug.WriteLine($"\nDataBaseHelperClass: {System.Reflection.MethodBase.GetCurrentMethod()}");
  
          int testint = 44;
          GantChartUserControl objGantChartUserControl = new GantChartUserControl();
          objGantChartUserControl.CreateTimeLine(testint);
      }
  </code></pre>