これが古い投稿であることを感謝しますが、今日これに出くわし、日付と時刻のバインドを処理する別の方法を見つけました。
日付用、時間用、分用の 4 つのプロパティを持つ dateTime という部分クラスを作成しました。次に、完了した日付を返す読み取り専用の dateTime プロパティ。
Partial Public Class dateTimeValue
Property Dt As Date
Property Hr As Integer
Property Mn As Integer
ReadOnly Property dateTime As Date
Get
Dim d = Dt
d = d.AddHours(d.Hour * -1).AddHours(Hr)
d = d.AddMinutes(d.Minute * -1).AddMinutes(Mn)
d = d.AddSeconds(d.Second * -1)
Return d
End Get
End Property
End Class
次に、XAML で、DateTimePicker といくつかの ComboBox へのバインディングを含むグリッド レイアウトを使用しました。
<UniformGrid Columns="2">
<TextBlock Text="Date"/>
<DatePicker SelectedDate="{Binding dateTime.Dt}"/>
<TextBlock Text="Time"/>
<WrapPanel>
<ComboBox SelectedValue="{Binding dateTime.Hr}" SelectedValuePath="Content">
<ComboBoxItem>00</ComboBoxItem>
<ComboBoxItem>01</ComboBoxItem>
<ComboBoxItem>02</ComboBoxItem>
.........
<ComboBoxItem>22</ComboBoxItem>
<ComboBoxItem>23</ComboBoxItem>
</ComboBox>
<TextBlock Text=":"/>
<ComboBox SelectedValue="{Binding dateTime.Mn}" SelectedValuePath="Content">
<ComboBoxItem>00</ComboBoxItem>
<ComboBoxItem>15</ComboBoxItem>
<ComboBoxItem>30</ComboBoxItem>
<ComboBoxItem>45</ComboBoxItem>
</ComboBox>
</WrapPanel>
<Button Click="saveTask" Content="Save Task"/>
</UniformGrid>
次に、たとえばテキストブロックに正しい日付と時刻を表示するには、使用できます
<TextBlock Text="{Binding dateTime.dateTime, StringFormat={}{0:dd MMM yyyy - HH:mm}}"/>
これが他の誰かを助けることを願っています。