You can use a value converter to hold on to the value
public class DateConverter : IValueConverter
{
private DateTime timePickerDate;
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
timePickerDate = ((DateTime)(value));
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return timePickerDate;
var datePickerDate = ((DateTime)(value));
// compare relevant parts manually
if (datePickerDate.Hour != timePickerDate.Hour
|| datePickerDate.Minute != timePickerDate.Minute
|| datePickerDate.Second != timePickerDate.Second)
{
// correct the date picker value
var result = new DateTime(datePickerDate.Year,
datePickerDate.Month,
datePickerDate.Day,
timePickerDate.Hour,
timePickerDate.Minute,
timePickerDate.Second);
// return, because this event handler will be executed a second time
return result;
}
return datePickerDate;
}
}
And have the two controls in question bind to the one property but have the date picker use the converter to not override the time.
<Grid Margin="10,5" >
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<sdk:DatePicker Grid.Column="0" TabIndex="1" Padding="0" SelectedDate="{Binding EffectiveDate, Mode=TwoWay, Converter={StaticResource DateConverter}}" SelectedDateFormat="Short"/>
<toolkit:TimePicker Grid.Column="1" Value="{Binding EffectiveDate, Mode=TwoWay}" Margin="0" Padding="0" HorizontalAlignment="Left" TabIndex="2" />
</Grid>