fork download
  1.  
  2. Imports System.Windows.Controls.Primitives
  3. Imports System.ComponentModel
  4.  
  5.  
  6. Public Class TextBox2nd
  7. Inherits System.Windows.Controls.TextBox
  8.  
  9. Shared Sub New()
  10. 'この OverrideMetadata 呼び出しは、この要素が基本クラスと異なるスタイルを提供することをシステムに通知します。
  11. 'このスタイルは themes\generic.xaml に定義されています
  12. DefaultStyleKeyProperty.OverrideMetadata(GetType(TextBox2nd), New FrameworkPropertyMetadata(GetType(TextBox)))
  13. End Sub
  14.  
  15. #Region "日付"
  16.  
  17. Public Shared ReadOnly DateValueProperty As DependencyProperty = DependencyProperty.Register( _
  18. "DateValue", _
  19. GetType(Date?), _
  20. GetType(TextBox2nd), _
  21. New PropertyMetadata(New PropertyChangedCallback(AddressOf OnDateChanged)))
  22.  
  23. Public Property DateValue() As Date?
  24. Get
  25. Return DirectCast(GetValue(DateValueProperty), Date?)
  26. End Get
  27. Set(ByVal value As Date?)
  28. SetValue(DateValueProperty, value)
  29.  
  30. End Set
  31. End Property
  32.  
  33. Private Shared Sub OnDateChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
  34. Dim textbox2 As TextBox2nd = DirectCast(d, TextBox2nd)
  35. If DirectCast(e.NewValue, Date?).HasValue Then
  36. textbox2.SetValue(TextBox2nd.TextProperty, DirectCast(e.NewValue, Date?).Value.ToString("yyyy/MM"))
  37. Else
  38. textbox2.SetValue(TextBox2nd.TextProperty, String.Empty)
  39. End If
  40. End Sub
  41.  
  42. #End Region
  43.  
  44. #Region "Text"
  45.  
  46. Public Shared Shadows ReadOnly TextProperty As DependencyProperty = DependencyProperty.Register( _
  47. "Text", _
  48. GetType(String), _
  49. GetType(TextBox2nd), _
  50. New PropertyMetadata(New PropertyChangedCallback(AddressOf OnTextChanged)))
  51.  
  52. Private Shared Shadows Sub OnTextChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
  53. Dim textbox2 As TextBox2nd = DirectCast(d, TextBox2nd)
  54. Dim str As String = DirectCast(e.NewValue, String)
  55. Dim dt As Date
  56. If Date.TryParse(str, dt) Then
  57. textbox2.SetValue(TextBox2nd.DateValueProperty, dt)
  58. Else
  59. textbox2.SetValue(TextBox2nd.DateValueProperty, Nothing)
  60. End If
  61. End Sub
  62.  
  63. #End Region
  64.  
  65. End Class
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty