代码中的OneTime绑定是否与直接设置本地值不同?

时间:2013-06-11 19:18:20

标签: c# silverlight windows-phone-7 windows-phone-8

OneTime 绑定有什么区别:

//Create the source string
string s = "Hello";

//Create the binding description
Binding b = new Binding("");
b.Mode = BindingMode.OneTime;
b.Source = s;

//Attach the binding to the target
MyText.SetBinding(TextBlock.TextProperty, b);

这个?

MyText.Text = s;

1 个答案:

答案 0 :(得分:1)

它非常不同。通过第二种方法,您可以在代码中的任何时间点更改边界值。但是通过一次时间绑定,仅在应用程序启动或数据上下文更改时评估绑定值。 请参阅OneTime绑定说明here