" UpdateSourceTrigger = PropertyChanged的"相当于一个Windows Phone 7的文本框 [英] "UpdateSourceTrigger=PropertyChanged" equivalent for a Windows Phone 7 TextBox
问题描述
有没有办法让Windows Phone 7的一个TextBox更新绑定在用户键入每一个字母,而不是失去焦点后?
像下面的文本框中WPF会做:
<文本框的文本={绑定路径= TextProperty,UpdateSourceTrigger =的PropertyChanged}/>
对于Silverlight的WP7不支持你所列出的语法。执行以下操作来代替:
<文本框框TextChanged =OnTextBoxTextChanged
文本={结合MYTEXT,模式=双向,
UpdateSourceTrigger =明确}/>
UpdateSourceTrigger =明确
这里是一个聪明的奖金。 这是什么? Explicit:更新只有当你调用UpdateSource
方法绑定源。当用户离开它可以节省你一个额外的绑定集的文本框
。
块引用>在C#中:
OnTextBoxTextChanged私人无效(对象发件人,TextChangedEventArgs E)
{
文本框的textBox =发件人的文本框;
//更新绑定源
BindingEx pression bindingExpr = textBox.GetBindingEx pression(TextBox.TextProperty);
bindingExpr.UpdateSource();
}Is there a way to get a TextBox in Windows Phone 7 to update the Binding as the user types each letter rather than after losing focus?
Like the following WPF TextBox would do:
<TextBox Text="{Binding Path=TextProperty, UpdateSourceTrigger=PropertyChanged}"/>
解决方案Silverlight for WP7 does not support the syntax you've listed. Do the following instead:
<TextBox TextChanged="OnTextBoxTextChanged" Text="{Binding MyText, Mode=TwoWay, UpdateSourceTrigger=Explicit}" />
UpdateSourceTrigger = Explicit
is a smart bonus here. What is it? Explicit: Updates the binding source only when you call theUpdateSource
method. It saves you one extra binding set when the user leaves theTextBox
.In C#:
private void OnTextBoxTextChanged( object sender, TextChangedEventArgs e ) { TextBox textBox = sender as TextBox; // Update the binding source BindingExpression bindingExpr = textBox.GetBindingExpression( TextBox.TextProperty ); bindingExpr.UpdateSource(); }
这篇关于&QUOT; UpdateSourceTrigger = PropertyChanged的&QUOT;相当于一个Windows Phone 7的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!