Wpf 将DependencyProperty绑定到DependencyProperty仅在一个方向上工作

Wpf 将DependencyProperty绑定到DependencyProperty仅在一个方向上工作,wpf,binding,Wpf,Binding,我将WPF与C#一起使用。 我有一个自定义控件,其中包含一个文本框。自定义控件具有dependencyproperty FilterText。ViewModel的CurrentText属性绑定到控件的FilterText属性 目标是当TextBox的Text属性更改时,更新我的ViewModel的CurrentText属性 问题:更新文本框的文本不会更新控件的FilterText DP。但是,更改FilterText属性会更新文本框的文本 自定义用户控件: <UserControl x:N

我将WPF与C#一起使用。 我有一个自定义控件,其中包含一个文本框。自定义控件具有dependencyproperty FilterText。ViewModel的CurrentText属性绑定到控件的FilterText属性

目标是当TextBox的Text属性更改时,更新我的ViewModel的CurrentText属性

问题:更新文本框的文本不会更新控件的FilterText DP。但是,更改FilterText属性会更新文本框的文本

自定义用户控件:

<UserControl x:Name="generalQuickSearch" (..)>
(..)
     <TextBox Text="{Binding FilterText, ElementName=generalQuickSearch, Mode=TwoWay}"/>
(..)
</UserControl>
 public static readonly DependencyProperty FilterTextProperty = DependencyProperty.Register("FilterText", typeof(string), typeof(GeneralQuickSearch));
在我看来,使用自定义控件:

<controls:GeneralQuickSearch FilterText="{Binding CurrentText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

使用Snoop,当我在文本框中输入文本时:

我的generalQuickSearch控件上的FilterText属性:


我不明白这为什么不起作用。感谢您的帮助。

找到了问题和解决方案:默认情况下,TextBox的文本属性仅在LostFocus更新。可以通过将以下内容添加到绑定来更改:

UpdateSourceTrigger=PropertyChanged
资料来源:

默认值为default,它返回目标依赖项属性的默认UpdateSourceTrigger值。但是,大多数依赖项属性的默认值为PropertyChanged,而Text属性的默认值为LostFocus