问题是如何设置依赖属性以将其绑定到任何其他依赖属性并稍后释放它。
UserControl1 中有一个依赖属性
#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
公共共享类中的一个依赖属性。
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(代码隐藏)上,需要取消注册旧的用户控件并注册新的选定用户控件,以使用新用户控件的属性设置 Shared MyPublicClass。
如何在代码隐藏中手动取消注册和注册依赖属性?
*解决了*
Dim myDataObject As New MyData(DateTime.Now)
Dim myBinding As New Binding("MyDataProperty")
myBinding.Source = myDataObject
BindingOperations.SetBinding(myText, TextBlock.TextProperty, myBinding)