DataGrid,TextBox - 绑定和即时更新 [英] DataGrid , TextBox - binding and instant updates

查看:430
本文介绍了DataGrid,TextBox - 绑定和即时更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程式包含图片中的窗口:

My app. contains the window in the picture:

DataGrid的ItemsSource设置为_editList(声明为IList< Vendor> _editList; )。

The ItemsSource of the DataGrid is set to _editList ( declared as IList < Vendor > _editList;).

数据网格设置为只读

供应商名称文本框具有绑定集:
Text ={Binding ElementName = dataGridVendors,Path = SelectedItem.Name,Mode = TwoWay}

The Vendor Name text box has the binding set as : Text="{Binding ElementName=dataGridVendors, Path=SelectedItem.Name, Mode=TwoWay}"

这个效果很好。但是,由于供应商名称单元格仅在用户完成供应商名称文本框中键入并点击其他内容时才会更新。说我想将供应商名称更改为John Lennon II。我必须单击文本框,并键入我要添加的字符,而不是我必须单击别的东西,然后只有datagrid进行更新。

This works well. However, as it is the Vendor Name cell only updates when the user is done typing in the Vendor Name textbox and clicks on something else. Say I want to change the vendor name to "John Lennon II" . I have to click on the textbox and type the characters I want to add and than I have to click on something else and only then the datagrid makes the update.

我想让用户键入字符发生更新....这是可能的吗?

I want to make the update happen as the user types the characters....Is this possible ?

Regards,
Sebastian

Regards, Sebastian

推荐答案

添加UpdateSourceTrigger到你的绑定

Add the UpdateSourceTrigger to your Binding

Text="{Binding ElementName=dataGridVendors, Path=SelectedItem.Name, Mode=TwoWay,  UpdateSourceTrigger=PropertyChanged}"

其默认触发器丢失焦点。当您将其更改为PropertyChanged时,您将在打字时完成更新。

Its default trigger is lost focus. When you change it to PropertyChanged the Updates will done when you're typing.

这篇关于DataGrid,TextBox - 绑定和即时更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆