“UpdateSourceTrigger = PropertyChanged”等效于WinRT-XAML中的TextBox [英] “UpdateSourceTrigger=PropertyChanged” equivalent for a TextBox in WinRT-XAML

查看:133
本文介绍了“UpdateSourceTrigger = PropertyChanged”等效于WinRT-XAML中的TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WPF中,只要用户通过使用UpdateSourceTrigger对数据进行任何更改,就可以更新底层数据模型:

 < TextBox Text ={Binding Path = TextProperty,UpdateSourceTrigger = PropertyChanged}/> 

在Window Phone UpdateSourceTrigger没有包含在XAML规范中,并且完成相同的,一个TextChanged处理程序是必须这样:

 (发件人为TextBox).GetBindingExpression(TextBox.TextProperty).UpdateSource(); 

在Windows 8中,我认为UpdateSourceTrigger也将被省略 - 我是正确的。但是,我感到惊讶的是,GetBindingExpression()也缺少。



在Windows 8中,最好的技术是什么,在WPF中用UpdateSourceTrigger并在Windows Phone中使用GetBindingExpression()。UpdateSource()?


请注意:此问题适用于Windows 8(Metro)开发;这个其他问题(UpdateSourceTrigger = PropertyChanged等同于Windows电话7文本框)用于Windows Phone开发 - 不要混淆。


作为研究问题,此示例(我创建的)使用TextBox覆盖来交换导致更新的两个属性之间的文本值。它基于。但是,有没有更好的方法?一些优雅的东西?

解决方案

似乎没有 GetBindingExpression 或等效的解决方法。但是,您可以这样扩展TextBox: https://mytoolkit.svn。 codeplex.com/svn/WinRT/Controls/ExtendedTextBox.cs



仍然这不能解决问题本身...(真的很伤心)



另见:




In WPF, we can update the underlying data model whenever the user makes any change to the data by leveraging UpdateSourceTrigger like this:

<TextBox Text="{Binding Path=TextProperty, UpdateSourceTrigger=PropertyChanged}"/>

In Window Phone UpdateSourceTrigger was not included in the XAML specification and to accomplish the same, a TextChanged handler was necessary like this:

(sender as TextBox).GetBindingExpression(TextBox.TextProperty).UpdateSource();

In Windows 8, I assumed that UpdateSourceTrigger would also be omitted - I was correct. I was surprised, however, to learn that GetBindingExpression() was also missing.

What is the best technique to accomplish, in Windows 8, what we accomplished in WPF with UpdateSourceTrigger and in Windows Phone with GetBindingExpression().UpdateSource()?

Please note: This question is for Windows 8 (Metro) development; this other question ( "UpdateSourceTrigger=PropertyChanged" equivalent for a Windows Phone 7 TextBox ) is for Windows Phone development - not to be confused.

As a matter of research, this example (which I created) uses a TextBox override to swap the text value between two properties causing the update. It is based on this. But, is there a better way? Something elegant?

解决方案

It seems there is no GetBindingExpression or equivalent workaround. However you can extend the TextBox like this: https://mytoolkit.svn.codeplex.com/svn/WinRT/Controls/ExtendedTextBox.cs

Still this doesn't solve the problem itself... (it's really sad)

See also:

这篇关于“UpdateSourceTrigger = PropertyChanged”等效于WinRT-XAML中的TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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