問題は、依存関係プロパティを設定して、他の依存関係プロパティにバインドし、後で解放する方法です。
UserControl1には1つの依存関係プロパティがあります
#Region "INotifyPropertyChanged Members"
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Protected Sub RaisePropertyChanged(ByVal name As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))
End Sub
#End Region
#Region "BorderSize"
Dim _BorderSize As Double = 1
''' <summary>
''' Gets or sets the BorderSize property. This observable property
''' indicates ....
''' </summary>
Public Overridable Property BorderSize() As Double
Get
Return _BorderSize
End Get
Set(ByVal value As Double)
If _BorderSize <> value Then
_BorderSize = value
RaisePropertyChanged("BorderSize")
End If
End Set
End Property
#End Region
パブリック共有クラスの1つの依存関係プロパティ。
Public Class MyPublicClass
Implements INotifyPropertyChanged
#Region "INotifyPropertyChanged Members"
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Protected Sub RaisePropertyChanged(ByVal name As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))
End Sub
#End Region
#Region "BorderSize"
Dim _BorderSize As Double = 1
''' <summary>
''' Gets or sets the BorderSize property. This observable property
''' indicates ....
''' </summary>
Public Property BorderSize() As Double
Get
Return _BorderSize
End Get
Set(ByVal value As Double)
If _BorderSize <> value Then
_BorderSize = value
RaisePropertyChanged("BorderSize")
End If
End Set
End Property
#End Region
End Class
MainWindow.xaml.vb(Codebehind)では、古いusercontrolの登録を解除し、新しく選択したusercontrolを登録して、SharedMyPublicClassを新しいusercontrolのプロパティでセットアップする必要があります。
コードビハインドで依存関係プロパティを手動で登録解除して登録するにはどうすればよいですか?
*解決しました*
Dim myDataObject As New MyData(DateTime.Now)
Dim myBinding As New Binding("MyDataProperty")
myBinding.Source = myDataObject
BindingOperations.SetBinding(myText, TextBlock.TextProperty, myBinding)