WPF数据绑定后点击保存按钮 [英] WPF databinding after Save button click
问题描述
在保存按钮单击之后,是否有任何优雅和类似WPF的数据绑定方式?
现在,在更改文本框的内容后立即进行数据绑定,我希望该单例具有旧值,并在点击保存按钮后更新它们。
对于 Textbox
在XAML中使用的 DataBinding
对象,请使用 code> UpdateSourceTrigger 属性,值为显式
如下:
< TextBox Name =itemNameTextBox
Text ={Binding Path = ItemName,UpdateSourceTrigger = Explicit}/>
将UpdateSourceTrigger值设置为Explicit时,源值仅在应用程序调用 UpdateSource
方法如下(您可以将以下代码放在Save 中单击
事件):
BindingExpression be = itemNameTextBox.GetBindingExpression(TextBox.TextProperty);
be.UpdateSource();
I have an app and a Settings window with TabControl containing couple of TabItems. Each of them have some fields (textboxes) which are databinded to the same Singleton object.
Is there any elegant and WPF-like way to the the databinding only after Save button click?
Right now it's databinded immediately after changing the content of the textbox, and I want that singleton have old values and update them only after clicking the save button.
For your DataBinding
object used in XAML for the Textbox
, use the UpdateSourceTrigger
property with value Explicit
as below:
<TextBox Name="itemNameTextBox"
Text="{Binding Path=ItemName, UpdateSourceTrigger=Explicit}" />
When you set the UpdateSourceTrigger value to Explicit, the source value only changes when the application calls the UpdateSource
method as below (you can put below code in Save Click
event):
BindingExpression be = itemNameTextBox.GetBindingExpression(TextBox.TextProperty);
be.UpdateSource();
这篇关于WPF数据绑定后点击保存按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!