为什么数据绑定不与工作的PropertyChanged? [英] Why data binding is not working with PropertyChanged?

查看:118
本文介绍了为什么数据绑定不与工作的PropertyChanged?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的XAML和Windows 8手机的发展和学习有关数据绑定。 这里,有人建议我需要使用,

I am new to XAML and Windows 8 phone development and learning about data binding. Here, it is suggested that I need to use,

UpdateSourceTrigger=PropertyChanged

但是,当我尝试使用它在我的XAML中,它给错误为请求值的PropertyChanged找不到。相反,它与

But when I try to use it in my xaml, it is giving error as 'Requested value 'PropertyChanged' not found.' Instead it is working correctly with,

UpdateSourceTrigger=Default

我做错了什么,或者是在新版本中已过时。

I am doing something wrong, or it is deprecated in newer versions.

我的代码示例,

 <TextBox x:Name="txt1" Height="100" Width="100"></TextBox>

 <TextBlock Grid.Row="1" x:Name="txt2" Height="100" Width="100" 
    Text="{Binding Text,ElementName=txt1,
 UpdateSourceTrigger=PropertyChanged}"></TextBlock>



感谢。

Thanks.

推荐答案

UpdateSourceTrigger = PropertyChanged的未在Windows Phone的XAML支持。

UpdateSourceTrigger=PropertyChanged is not supported in Windows Phone XAML.

您可以使用 UpdateSourceTrigger =明确代替,
和处理后面的代码的源代码的更新:

You can use UpdateSourceTrigger=Explicit instead, and handle the source updating in the code behind:

private void OnTextBoxTextChanged( object sender, TextChangedEventArgs e )
{
  TextBox textBox = sender as TextBox;
  BindingExpression bindingExpr = textBox.GetBindingExpression( TextBox.TextProperty );
  bindingExpr.UpdateSource();
}



另一种方法是使用的 Coding4Fun图书馆 BindingHelper。在这种情况下,语法是:

Another alternative would be to use Coding4Fun's library BindingHelper. in that case, the syntax would be:

<TextBox   
  Text="{Binding FooBar, Mode=TwoWay}" 
  local:TextBinding.UpdateSourceOnChange="True" />

这篇关于为什么数据绑定不与工作的PropertyChanged?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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