WPF 附加 属性 样式在 VB.Net 中没有可访问的 Setter

WPF Attached Property in Style has no accessible Setter in VB.Net

我已经创建了一个依赖对象 Class:

Public Class TextMonitoring
Inherits DependencyObject

Public Shared ReadOnly MonitorTextProperty As DependencyProperty = DependencyProperty.RegisterAttached("MonitorText",
                                                               GetType(Boolean),
                                                               GetType(TextMonitoring),
                                                               New PropertyMetadata(False, New PropertyChangedCallback(AddressOf MonitorTextChanged)))

Public Shared Function GetMonitorTextProperty(sender As DependencyObject) As Boolean
    Return CType(sender, PasswordBox).GetValue(MonitorTextProperty)
End Function

Public Shared Sub SetMonitorTextProperty(sender As DependencyObject)
    CType(sender, PasswordBox).SetValue(MonitorTextProperty, True)
End Sub

Public Shared Function GetMonitorText(sender As DependencyObject) As Boolean
    Return CType(sender, PasswordBox).GetValue(MonitorTextProperty)
End Function

Public Shared Sub SetMonitorText(sender As DependencyObject)
    CType(sender, PasswordBox).SetValue(MonitorTextProperty, True)
End Sub

Public Shared Sub MonitorTextChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)

End Sub

结束Class

我的样式包含 Setter:

    xmlns:local="clr-namespace:TestAttachedProperty">

<Style TargetType="{x:Type PasswordBox}">

    <Setter Property="FontSize" Value="24" />
    <Setter Property="Padding" Value="10" />
    <Setter Property="Margin" Value="0 5 0 5" />

    <Setter Property="local:TextMonitoring.MonitorText" Value="True" />

编译出现错误:XDG0013: 属性 "MonitorText" 没有可访问的 setter.

我做错了什么?

Set* 和 Get* 访问器应该只设置和获取附加的值 属性:

Public Class TextMonitoring
    Inherits DependencyObject

    Public Shared ReadOnly MonitorTextProperty As DependencyProperty = DependencyProperty.RegisterAttached("MonitorText",
                                                                    GetType(Boolean),
                                                                    GetType(TextMonitoring),
                                                                    New FrameworkPropertyMetadata(False, New PropertyChangedCallback(AddressOf MonitorTextChanged)))
    Public Shared Sub SetMonitorText(ByVal element As DependencyObject, ByVal value As Boolean)
        element.SetValue(MonitorTextProperty, value)
    End Sub
    Public Shared Function GetMonitorText(ByVal element As DependencyObject) As Boolean
        Return CType(element.GetValue(MonitorTextProperty), Boolean)
    End Function

    Private Shared Sub MonitorTextChanged(sender As DependencyObject, e As DependencyPropertyChangedEventArgs)

    End Sub

End Class