title: Binding MVVM Command to TimePicker control in UWP
body: <p>I'm using a <code>TimePicker</code> control on a XAML page and try to react on changes in the corresponding <code>ViewModel</code>. I added the <code>Xaml.Interactivity</code> and <code>Xaml.Interactivity.Core</code> namespace to my page in order to use the <code>Behaviors SDK</code> to trigger the command once the <code>TimeChanged</code> event is called.</p>
  
  <pre><code>&lt;!-- XAML Namespaces --&gt;
  xmlns:interact="using:Microsoft.Xaml.Interactivity"
  xmlns:interactcore="using:Microsoft.Xaml.Interactions.Core"
  
  &lt;TimePicker x:Name="TestTimePicker" ClockIdentifier="24HourClock" Time="0"&gt;
      &lt;interact:Interaction.Behaviors&gt;
          &lt;interactcore:EventTriggerBehavior EventName="TimeChanged"&gt;
              &lt;interactcore:InvokeCommandAction Command="{Binding DataContext.TimeChangedCommand}" CommandParameter="{Binding ElementName=TestTimePicker, Path=Time}" /&gt;
          &lt;/interactcore:EventTriggerBehavior&gt;
      &lt;/interact:Interaction.Behaviors&gt;
  &lt;/TimePicker&gt;
  </code></pre>
  
  <p>For the code in my <code>ViewModel</code> I use <code>ViewModelBase</code> and <code>DelegateCommand</code> from <code>Template10</code>.</p>
  
  <pre><code>public DelegateCommand&lt;TimeSpan&gt; StartTimeChangedCommand { get; set; }
  
  public TestViewModel()
  {
      ...
      TimeChangedCommand = new DelegateCommand&lt;TimeSpan&gt;(TimeChangedAction);
      ...
  }
  
  private void TimeChangedAction(TimeSpan obj)
  {
      //do something with obj
  }
  </code></pre>
  
  <p>Once the Page is Initialized a <code>InvalidOperationException</code> with the following message gets thrown.</p>
  
  <pre><code>Adding or removing event handlers dynamically is not supported on WinRT events.
  </code></pre>