fork download
  1. [ValueConversion(typeof(DateTime), typeof(string))]
  2. class DateTimeConverter1 : Freezable, IValueConverter
  3. {
  4. // Convertは問題なし。
  5. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  6. {
  7. // DateTime型 -> HH:ss (時刻だけを表示する)
  8. var d = System.Convert.ToDateTime(value);
  9. return d.ToString("HH:ss");
  10. }
  11.  
  12. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  13. {
  14. // valueにはテキストボックスに入力したstring型の時刻(HH:mm)が入っている。
  15.  
  16. DateTime time = System.Convert.ToDateTime(value.ToString());
  17. DateTime date = Date; // HogeDateの値
  18.  
  19. // return ~
  20. }
  21.  
  22.  
  23. public DateTime Date
  24. {
  25. get { return (DateTime)GetValue(DayProperty); }
  26. set { SetValue(DayProperty, value); }
  27. }
  28. public static readonly DependencyProperty DayProperty =
  29. DependencyProperty.Register("Date", typeof(DateTime), typeof(DateTimeConverter1));
  30.  
  31. protected override Freezable CreateInstanceCore()
  32. {
  33. return new DateTimeConverter1();
  34. }
  35. }
  36.  
  37.  
  38. <Window.Resources>
  39. <v:DateTimeConverter1 x:Key="converter1" Date="{Binding HogeDate}" />
  40. </Window.Resources>
  41.  
  42. <TextBox Text="{Binding HogeDate,Converter={StaticResource converter1}}"/>
  43.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty