Я предполагаю, что ваш класс основан на классе C #, похожем на приведенный здесь:
https://www.csharpcodi.com/vs2/306/fasetto-word/Source/Fasetto.Word/AttachedProperties/BaseAttachedProperty.cs/#
В вашем коде две функции OnValuePropertyChanged и OnValuePropertyUpdated вызывают методValueUpdated.
Private Shared Sub OnValuePropertyChanged(d As DependencyObject, e As DependencyPropertyChangedEventArgs)
TryCast(Instance, BaseAttachedProperty(Of Parent, [Property]))?.OnValueChanged(d, e)
TryCast(Instance, BaseAttachedProperty(Of Parent, [Property]))?.ValueChanged(d, e)
End Sub
Private Shared Function OnValuePropertyUpdated(d As DependencyObject, value As Object) As Object
TryCast(Instance, BaseAttachedProperty(Of Parent, [Property]))?.OnValueUpdated(d, value)
TryCast(Instance, BaseAttachedProperty(Of Parent, [Property]))?.ValueUpdated(d, value)
Return value
End Function
Если я прав насчет исходного кода C #, то ValueUpdated на самом деле является событием, а не методом.
В VB.NET вы не можете вызвать событие с этим синтаксисом, выЯ должен использовать оператор RaiseEvent.
Я не думаю, что есть прямой способ вызвать событие из статического метода в VB.NET.Я бы порекомендовал определить нестатический член и вызвать его через указатель экземпляра.
Private Shared Sub OnValuePropertyChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
TryCast(Instance, BaseAttachedProperty(Of Parent, [Property]))?.OnValueChanged(d, e)
TryCast(Instance, BaseAttachedProperty(Of Parent, [Property]))?.FireValueChanged(d, e)
End Sub
Private Sub FireValueChanged ( d As DependencyObject, value As DependencyPropertyChangedEventArgs )
RaiseEvent ValueUpdated ( d, value )
End Sub
В качестве альтернативы вы можете вызвать событие из метода OnValueChanged.
Это полный класс, который я сгенерировал путем автоматического преобразования кода C #, а затем исправил ошибки компиляции.
Imports System
Imports System.ComponentModel
Imports System.Windows
Public MustInherit Class BaseAttachedProperty(Of Parent As New, [Property])
Public Event ValueChanged As Action(Of DependencyObject, DependencyPropertyChangedEventArgs)
Public Event ValueUpdated As Action(Of DependencyObject, Object)
Public Shared Property Instance As Parent = New Parent()
Private Shared defValue As [Property] = Nothing
Public Shared ReadOnly ValueProperty As DependencyProperty _
= DependencyProperty.RegisterAttached ( "Value", _
GetType([Property]), _
GetType(BaseAttachedProperty(Of Parent, [Property])), _
New UIPropertyMetadata ( defValue, _
New PropertyChangedCallback(AddressOf OnValuePropertyChanged), _
New CoerceValueCallback(AddressOf OnValuePropertyUpdated)) )
Public Property Value as [Property]
Private Shared Sub OnValuePropertyChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
TryCast(Instance, BaseAttachedProperty(Of Parent, [Property]))?.OnValueChanged(d, e)
TryCast(Instance, BaseAttachedProperty(Of Parent, [Property]))?.FireValueChanged(d, e)
End Sub
Private Shared Function OnValuePropertyUpdated(ByVal d As DependencyObject, ByVal value As Object) As Object
TryCast(Instance, BaseAttachedProperty(Of Parent, [Property]))?.OnValueUpdated(d, value)
TryCast(Instance, BaseAttachedProperty(Of Parent, [Property]))?.FireValueUpdated(d, value)
Return value
End Function
Private Sub FireValueChanged ( d As DependencyObject, value As DependencyPropertyChangedEventArgs )
RaiseEvent ValueChanged ( d, value )
End Sub
Private Sub FireValueUpdated ( d As DependencyObject, value As [Property] )
RaiseEvent ValueUpdated ( d, value )
End Sub
Public Shared Function GetValue(ByVal d As DependencyObject) As [Property]
Return CType(d.GetValue(ValueProperty), [Property])
End Function
Public Shared Sub SetValue(ByVal d As DependencyObject, ByVal value As [Property])
d.SetValue(ValueProperty, value)
End Sub
Public Overridable Sub OnValueChanged(ByVal sender As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
End Sub
Public Overridable Sub OnValueUpdated(ByVal sender As DependencyObject, ByVal value As Object)
End Sub
End Class
Я проверил этот код с использованием трех определений атрибутов
Public Class ControlDescriptionProperty
Inherits BaseAttachedProperty(Of ControlDescriptionProperty, String)
End Class
Public Class ControlTitleProperty
Inherits BaseAttachedProperty(Of ControlTitleProperty, String)
End Class
Public Class NumericInputProperty
Inherits BaseAttachedProperty(Of NumericInputProperty, Boolean)
End Class
При использовании следующего кода XAML он не генерирует ошибку во время выполнения или в конструкторе: