WinRT-XAML 中文本框的“UpdateSourceTrigger=PropertyChanged"等效项 [英] “UpdateSourceTrigger=PropertyChanged” equivalent for a TextBox in WinRT-XAML

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

问题描述

在 WPF 中,每当用户对数据进行任何更改时,我们都可以通过利用 UpdateSourceTrigger 来更新底层数据模型,如下所示:

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}"/>

在 Window Phone 中,UpdateSourceTrigger 未包含在 XAML 规范中,为了实现相同的目的,需要一个 TextChanged 处理程序,如下所示:

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();

在 Windows 8 中,我假设 UpdateSourceTrigger 也将被省略 - 我是对的.然而,我很惊讶地发现 GetBindingExpression() 也不见了.

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.

在 Windows 8 中,我们在 WPF 中使用 UpdateSourceTrigger 和在 Windows Phone 中使用 GetBindingExpression().UpdateSource() 完成的最佳技术是什么?

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

请注意:此问题适用于 Windows 8 (Metro) 开发;另一个问题( UpdateSourceTrigger=PropertyChanged"相当于 WindowsPhone 7 TextBox ) 用于 Windows Phone 开发 - 不要混淆.

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.

作为研究问题,这个例子(我created) 使用 TextBox 覆盖在导致更新的两个属性之间交换文本值.它基于this.但是,有没有更好的办法?优雅的东西?

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?

推荐答案

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

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)

另见:

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

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