Imports System.Windows.Controls.Primitives


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

    Public Shared ReadOnly DateValueProperty As DependencyProperty = DependencyProperty.Register( _
          "DateValue", _
          GetType(Date?), _
          GetType(TextBox2nd), _
           New PropertyMetadata(), _
           New ValidateValueCallback(AddressOf DateChanged))

    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 Function DateChanged() As Boolean
        SetValue(TextProperty, DirectCast(GetValue(DateValueProperty), Date?))
        Return True
    End Function
    'どっちもエラー
    Private Function DateChanged() As Boolean
        SetValue(TextProperty, DirectCast(GetValue(DateValueProperty), Date?))
        Return True
    End Function

End Class