Imports System.Windows.Controls.Primitives
Imports System.ComponentModel
Public Class TextBox2nd
Inherits System.Windows.Controls.TextBox
Shared Sub New()
'この OverrideMetadata 呼び出しは、この要素が基本クラスと異なるスタイルを提供することをシステムに通知します。
'このスタイルは themes\generic.xaml に定義されています
DefaultStyleKeyProperty.OverrideMetadata(GetType(TextBox2nd), New FrameworkPropertyMetadata(GetType(TextBox)))
End Sub
#Region "日付"
Public Shared ReadOnly DateValueProperty As DependencyProperty = DependencyProperty.Register( _
"DateValue", _
GetType(Date?), _
GetType(TextBox2nd), _
New PropertyMetadata(New PropertyChangedCallback(AddressOf OnDateChanged)))
Public Property DateValue() As Date?
Get
Return DirectCast(GetValue(DateValueProperty), Date?)
End Get
Set(ByVal value As Date?)
SetValue(DateValueProperty, value)
End Set
End Property
Private Shared Sub OnDateChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
Dim textbox2 As TextBox2nd = DirectCast(d, TextBox2nd)
If DirectCast(e.NewValue, Date?).HasValue Then
textbox2.SetValue(TextBox2nd.TextProperty, DirectCast(e.NewValue, Date?).Value.ToString("yyyy/MM"))
Else
textbox2.SetValue(TextBox2nd.TextProperty, String.Empty)
End If
End Sub
#End Region
#Region "Text"
Public Shared Shadows ReadOnly TextProperty As DependencyProperty = DependencyProperty.Register( _
"Text", _
GetType(String), _
GetType(TextBox2nd), _
New PropertyMetadata(New PropertyChangedCallback(AddressOf OnTextChanged)))
Private Shared Shadows Sub OnTextChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
Dim textbox2 As TextBox2nd = DirectCast(d, TextBox2nd)
Dim str As String = DirectCast(e.NewValue, String)
Dim dt As Date
If Date.TryParse(str, dt) Then
textbox2.SetValue(TextBox2nd.DateValueProperty, dt)
Else
textbox2.SetValue(TextBox2nd.DateValueProperty, Nothing)
End If
End Sub
#End Region
End Class
CkltcG9ydHMgU3lzdGVtLldpbmRvd3MuQ29udHJvbHMuUHJpbWl0aXZlcwpJbXBv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