简体   繁体   English

wpf TextBox TexPreviewTextInput无法与绑定一起使用

[英]wpf TextBox TexPreviewTextInput not working with binding

I'm trying to catch TexPreviewTextInput event from TextBox on binding change and it doesn't work. 我试图在绑定更改时从TextBox捕获TexPreviewTextInput事件,但是它不起作用。 I want to be able to get the current value and the new value, I'm not changing some of the charterers, but the whole string with binding. 我希望能够获得当前值和新值,我没有更改某些租船合同,而是更改了具有约束力的整个字符串。

<TextBox x:Name="TB" Text="{Binding TBText}" PreviewTextInput="Sender_TexPreviewTextInput"/>

and the code behind is: 而后面的代码是:

    public MainWindow()
    {
        InitializeComponent();
        TB.Text = "First Value";
        Loaded+=MainWindow_Loaded;
    }

    public string  TBText { get; set; }

    void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        TB.Text = "Changed Value";
    }

    void Sender_TexPreviewTextInput(object sender, TextCompositionEventArgs e)
    {
        //Do Somthing
    }

PreviewTextInput event is raised whenever user input text via device (keyboard mostly). 每当用户通过设备 (主要是键盘) 输入文本时,都会引发PreviewTextInput事件。

If you are interested in whenever text changed from code behind or via binding or via device input, hook to TextChanged event. 如果您有兴趣在文本从代码后面更改,通过绑定更改或通过设备输入更改文本,请转至TextChanged事件。

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

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