私のwpfアプリケーションのCustomViewウィンドウで、宣言したプロパティは次のとおりです。
private DateTime starttime
{
get
{
return DateTime.Parse(StartTimeText.Text);
}
set
{
StartTimeText.Text = value.ToString();
OnPropertyChanged("starttime");
}
}
private DateTime stoptime
{
get
{
return DateTime.Parse(StopTimeText.Text);
}
set
{
StopTimeText.Text = value.ToString();
OnPropertyChanged("stoptime");
}
}
protected virtual void OnPropertyChanged(String time)
{
if (System.String.IsNullOrEmpty(time))
{
return;
}
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(time));
}
}
public event PropertyChangedEventHandler PropertyChanged;
xamlでは、
<DatePicker x:Name="StartTimeText"
SelectedDate="{Binding Path=starttime}"
BorderThickness="0"
Background="Yellow"
Width="100"/>
<DatePicker x:Name="StopTimeText"
SelectedDate="{Binding Path=stoptime, Mode=TwoWay}"
BorderThickness="0"
Background="Yellow"
Width="60"/>
このようにして、starttime コントロールと stoptime コントロールで Date を取得しています。しかし、「hh:mm tt」形式の時間が必要です。DateTimePicker コントロールは、WPF ツールボックスでは使用できません。日付の代わりに指定された形式で時間を取得するには、どうすればよいですか? 提案してください。