Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 代码中的一次性绑定与直接设置本地值不同吗?_C#_Silverlight_Windows Phone 7_Windows Phone 8 - Fatal编程技术网

C# 代码中的一次性绑定与直接设置本地值不同吗?

C# 代码中的一次性绑定与直接设置本地值不同吗?,c#,silverlight,windows-phone-7,windows-phone-8,C#,Silverlight,Windows Phone 7,Windows Phone 8,此一次性绑定之间有什么区别: //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);

一次性绑定之间有什么区别:

//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;

这很不一样。通过第二种方法,您可以在代码中的任何时间点更改绑定值。但使用一次性绑定时,绑定值仅在应用程序启动或数据上下文更改时计算。
请参阅一次性绑定说明。

但在字符串绑定的情况下,绑定值是不可变的,因此没有区别,对吗?绑定仅在与通知其值更改的属性一起使用时才有用,从而提供了一种简单的机制,使模型与视图结合起来。在您的案例中,您正在使用一个变量进行绑定。所以,即使您更改了变量的值,在您通知它之前,它也不会反映在视图元素中。这对于字符串或任何其他类型都是正确的。好的,那么我们可以说在我的问题中这两种方法之间没有区别?