我需要時間下表(「dd.MM.yyy」)和時間結合起來,並插入到一個DateTime對象:如何結合日期和時間WPF
例: 日期13/10/2017和TIME :10:30 - >聯合收割機日期結果:13/10/2017 10:30
XAML:
//DATE ("dd.MM.yyy")
<DatePicker HorizontalAlignment="Center"
Validation.ErrorTemplate="{StaticResource TextBoxErrorTemplate}"
SelectedDate="{Binding DeliveryDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged ,NotifyOnValidationError=True ,TargetNullValue=''}"/>
//TIME
<TextBox Validation.ErrorTemplate="{StaticResource TextBoxErrorTemplate}" >
<TextBox.Text >
<Binding Path="Time" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True" Mode="TwoWay" >
<Binding.ValidationRules>
<local:DateTimeValidationRule ValidationStep="RawProposedValue"/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
視圖模型:
public DateTime DeliveryDate;
private TimeSpan time;
public TimeSpan Time
{
get { return time; }
set
{
time = value;
OnPropertyChanged("Time");
}
}
public DateViewModel()
{ saveDate = new RelayCommand<string>(SaveDateFunction);
DeliveryDate = DateTime.Now.Date ;
}
public void SaveDateFunction(string obj)
{
DateTime combined = DeliveryDate.Add(Time);
}
我有錯誤結果:13/10/2017 00:00:00 我該如何解決它?
非常感謝,它的工作原理:) – TunNet