简体   繁体   English

绑定InputBindings后,TextEdit绑定变为null

[英]TextEdit Binding becomes null after binding InputBindings

I had a button and TextEdit like this, they were working correctly: 我有一个按钮和类似TextEdit的按钮,它们工作正常:

<dxe:TextEdit Text="{Binding SearchText}" />
<Button Command="{Binding SearchCommand}" / >

I wanted to make search when user hits Enter, so I changed my code this way : 我想在用户按下Enter键时进行搜索,因此我通过以下方式更改了代码:

<dxe:TextEdit Text="{Binding SearchText}"  >
                    <dxe:TextEdit.InputBindings>
                        <KeyBinding Key="Enter" Command="{Binding SearchCommand}"  />
                    </dxe:TextEdit.InputBindings>
                </dxe:TextEdit>
<Button Command="{Binding SearchCommand}">

This works, but in the code, SearchText is always null. 可行 ,但是在代码中, SearchText始终为null。 So I broke something when I added input bindings, can you tell me how to fix this? 因此,当我添加输入绑定时,我遇到了一些麻烦,您能告诉我如何解决此问题吗? I also tried this one, but SearchText is still null. 我也尝试过这个,但是SearchText仍然为null。

<KeyBinding Key="Enter" Command="{Binding SearchCommand}"  CommandParameter="{Binding Path=Text, RelativeSource={RelativeSource AncestorType={x:Type dxe:TextEdit}}}" />

If I remember correctly the default UpdateSourceTrigger property for DevExpress editors is LostFocus (I might be wrong on this) 如果我没有记错的话,DevExpress编辑器的默认UpdateSourceTrigger属性是LostFocus(对此我可能是错的)

And to make your code work, you have to force the source to update whenever the target value changes, by setting UpdateSourceTrigger to PropertyChangted. 为了使代码正常工作,必须通过将UpdateSourceTrigger设置为PropertyChangted来强制在目标值更改时更新源。

You can read more about UpdateSourceTrigger property on MSDN 您可以在MSDN上阅读有关UpdateSourceTrigger属性的更多信息。

Have you nofity about change in code? 您对代码更改有很高的评价吗? You have to do it by inheriting INotifyPropertyChanged interface in your class and invoke PropertyChangedEventHandler event; 您必须通过在类中继承INotifyPropertyChanged接口并调用PropertyChangedEventHandler事件来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM