title: WPF- TimePicker Binding to set date and time at runtime
body: <p>In my Wpf app, I've two TimePickers. I've used binding for them but their time is not updating. I also want to set selected date for these TimePickers.I tried to bind it as below. But, it won't work. Actual problem here is TimePickers are inside DataTemplate.</p>
  
  <p>Here is xaml:</p>
  
  <pre><code>&lt;DataTemplate x:Key="EditableDataTemplate"&gt;
    &lt;StackPanel Orientation="Horizontal" Width="596"&gt;
      &lt;xctk:TimePicker Name="StartPicker" Value="{Binding StartValue, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Format="Custom" FormatString="hh:mm tt" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" Width="100" EndTime="11:59:0"/&gt;
      &lt;xctk:TimePicker Name="EndPicker" Value="{Binding EndValue, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Format="Custom" FormatString="hh:mm tt" Background="Yellow" Padding="0" Margin="0" BorderThickness="0" Width="60" EndTime="11:59:0"/&gt;
    &lt;/StackPanel&gt;
  &lt;/DataTemplate&gt;
  </code></pre>
  
  <p>Binding with properits in C#:</p>
  
  <pre><code>    private DateTime _dateTime1;
      public DateTime StartValue
      {
          get
          {
              return _dateTime1;
          }
          set
          {
              _dateTime1 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
              OnPropertyChanged("StartValue");
          }
      }
  
      private DateTime _dateTime2;
      public DateTime EndValue
      {
          get
          {
              return _dateTime2;
          }
          set
          {
              _dateTime2 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
              OnPropertyChanged("EndValue");
          }
      }
  
      protected virtual void OnPropertyChanged(String time)
      {
          if (System.String.IsNullOrEmpty(time))
          {
              return;
          }
          if (PropertyChanged != null)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(time));
          }
      }
  
      #region INotifyPropertyChanged Members
      public event PropertyChangedEventHandler PropertyChanged;
      #endregion
  </code></pre>
  
  <p>Please suggest some ideas?</p>