我有一个控件,我用于我的新应用程序.此控件具有常规属性. Public Property Value() As String Get If AutoCompleteTextBox.SearchText Is Nothing Then Return String.Empty Else Return AutoCompleteTextBox.SearchText.ToString.T
Public Property Value() As String Get If AutoCompleteTextBox.SearchText Is Nothing Then Return String.Empty Else Return AutoCompleteTextBox.SearchText.ToString.Trim End If End Get Set(value As String) AutoCompleteTextBox.SearchText = value End Set End Property
编辑:
所以,经过多次尝试,我终于到了这个阶段.
Public Shared ValueProperty As DependencyProperty = DependencyProperty.Register("Value", GetType(String), GetType(AutoCompleteBox)) Public Property Value() As String Get Return Me.GetValue(ValueProperty).ToString End Get Set(value As String) Me.SetValue(ValueProperty, value) End Set End Property Public Event PropertyChanged As PropertyChangedEventHandler _ Implements INotifyPropertyChanged.PropertyChanged
这是依赖属性.此属性仍然没有约束力.输出窗口中没有显示绑定错误.
Text="{Binding RelativeSource={RelativeSource Self}, Path=Value, Mode=TwoWay}"
这是我的绑定方法.我不知道我还能做什么.至少如果出现错误,我本可以找到一些东西.没有任何错误,我只是一个没头的鸡.
有关所有依赖性基础知识,请参阅以下URLhttp://www.wpftutorial.net/dependencyproperties.html
基本上,您可以通过提供FrameworkPropertyMetadata来获取依赖项属性的属性更改事件.
new FrameworkPropertyMetadata( [Default Value], OnCurrentTimePropertyChanged);
您可以在事件处理程序中取回目标控件(DependencyObject)并在那里实现您的逻辑
private static void OnCurrentTimePropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs e) { AutoCompleteTextBox control = source as AutoCompleteTextBox; string time = (string)e.NewValue; // Put some update logic here... }