“UpdateSourceTrigger = PropertyChanged”等效于WinRT-XAML中的TextBox [英] “UpdateSourceTrigger=PropertyChanged” equivalent for a TextBox in WinRT-XAML
问题描述
< 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
仍然这不能解决问题本身...(真的很伤心)
另见:
- http://social.msdn.microsoft.com/Forums/en-US / winappswithcsharp / thread / a04dc907-9ca8-4302-bbad-c00b01b8193f /
- http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/69214cce-787b- 40c6-9d40-a556c5636119 /
- http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/775f1692-2837-471c-95fc-710bf0e9cc53
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:
- http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/a04dc907-9ca8-4302-bbad-c00b01b8193f/
- http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/69214cce-787b-40c6-9d40-a556c5636119/
- http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/775f1692-2837-471c-95fc-710bf0e9cc53
这篇关于“UpdateSourceTrigger = PropertyChanged”等效于WinRT-XAML中的TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!