title: Executing command in another viewmodel?
body: <p>I have a custom "DateRangeSelector" control derived from ComboBox. This is a drop-down control with the following filters:<br>
  1. Today<br>
  2. Next three days<br>
  3. Next three weeks<br>
  4. Custom Range(Allows the user to set a custom date range)  </p>
  
  <p>Now this "DateRangeSelector" control is added to another XAML(ActivityListMenuControlView.xaml) as:</p>
  
  <pre><code>&lt;DateRangeSelector:DateRangeSelectorControl x:Name="DateRangeSelector"
      Grid.Column="1"
      Margin="10 0 0 0"
      HorizontalAlignment="Left"
      VerticalAlignment="Center"
      AutomationProperties.AutomationId="AID_TaskListDateRangeSelector"
      DateRangeUpdatedCmd="{Binding Path=DateRangeSelectionUpdatedCommand}"
      TodayDateUpdatedCmd="{Binding Path=TodayDateUpdatedCommand}"
      FontSize="{StaticResource TaskListMenuFontSize}"
      RangeOptions="{Binding Path=DateRangeSelectionOptions,
      Mode=OneTime}"
      SelectedDateRange="{Binding Path=SelectedRange,
      Mode=TwoWay}"
      Visibility="{Binding Path=ShowFilterOptions,
      Converter={StaticResource boolToVisibility}}" /&gt;
  </code></pre>
  
  <p>As evident from the code above i have created a command "TodayDateUpdatedCmd" in "DateRangeSelector" intended to update the "Today" filter in this control whenever the system date changes and binded to the command "TodayDateUpdatedCommand" in "ActivityListMenuControlViewModel".<br>
  Code to update the date is there in the method "SetDateValues" in "DateRangeSelector" itself.
  I am just confused on how to excute this method from "ActivityListMenuControlViewModel"?
  Please help.</p>
  
  <p>UPDATE:
  DateRangeSelector is simply a class with no view/viewmodel. Here is the code:</p>
  
  <pre><code>public class DateRangeSelectorControl : ComboBox, INotifyPropertyChanged
  {
                    public static readonly DependencyProperty TodayDateUpdateCmdProperty = DependencyProperty.Register("TodayDateUpdatedCmd", typeof(ICommand), typeof(DateRangeSelectorControl),
      new PropertyMetadata(null));
  
      public ICommand TodayDateUpdatedCmd
      {
          get { return (ICommand)this.GetValue(TodayDateUpdateCmdProperty); }
          set
          {
              this.SetValue(TodayDateUpdateCmdProperty, value);
          }
      }
  
           /// &lt;summary&gt;
      /// 
      /// &lt;/summary&gt;
      private void SetDateValues()
      {
          DateTime todaysDate = DateTime.Now;
  
          TodayText = Utility.GetStringFromResource("TodayLabel") + " (" + todaysDate.ToShortDateString() + ")";
  
          NextThreeDaysText = Utility.GetStringFromResource("NextThreeDaysLabel") + " (" + todaysDate.ToShortDateString() + " - " + todaysDate.AddDays(3).ToShortDateString() + ")";
  
          NextWeekText = Utility.GetStringFromResource("NextWeekLabel") + " (" + todaysDate.ToShortDateString() + " - " + todaysDate.AddDays(7).ToShortDateString() + ")";
  
          SetCustomDateRangeText();
      }
  }
  </code></pre>
  
  <p>As evident from the code above, i have first registered a dependency property "TodayDateUpdateCmdProperty" and the command property "TodayDateUpdatedCmd" which is used in "ActivityListMenuControlView.xaml" as seen in the XAML snippet. Further i need to execute the method "SetDateValues" in DateRangeSelector class to update the today date.
  Now please help me out how to achieve this?</p>
  
  <p>UPDATE: 
  As per the suggestions from @GazTheDestroyer i made the changes into the code and now not using any command.But now getting the runtime XamlParseException with the below details:</p>
  
  <p>"'The invocation of the constructor on type 'VMS.Nexus.Client.Common.Controls.DateRangeSelector.DateRangeSelectorControl' that matches the specified binding constraints threw an exception.' Line number '45' and line position '14'."}</p>
  
  <p>InnerException:
  {"Default value type does not match type of property 'TodayDate'."}</p>
  
  <p>This exception is thrown in ActivityListMenuControlView.xaml where i created DateRangeSelector.
  Please help</p>