0
這是什麼一次性之間的差異綁定: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;
但是,在字符串綁定的情況下,綁定值是不可變的,所以它發生沒有區別,對吧? – MaxHype
綁定僅在與通知其值發生更改的屬性一起使用時纔有用,因此提供了一種簡便的機制來爲視圖膠凝模型。就你而言,你正在使用一個變量進行綁定。所以,即使你改變了變量的值,它也不會反映到你的視圖元素中,直到你通知它爲止。對於字符串或任何其他類型都是如此。 – gordanvij
好的,我們可以說在我的問題中兩種方法沒有區別嗎? – MaxHype