WP7:如何从代码中删除绑定?

gia*_*der 1 binding windows-phone-7

我有一个TextBlock tblControl,我想设置一个类似于xaml的绑定

Foreground="{Binding ForegroundColor}"

但在代码中.所以我使用:

var b = new Binding { Path = new PropertyPath("ForegroundColor") };
tblControl.SetBinding(TextBlock.ForegroundProperty, b);
Run Code Online (Sandbox Code Playgroud)

一切正常.

现在我想删除Binding以允许TextBlock显示默认的Foreground颜色,或者我需要设置Foreground的默认值.tblControl.SetBinding(TextBlock.ForegroundProperty, null);不管用.怎么做?

cal*_*lum 7

以下将清除绑定(或任何其他本地值):

tblControl.ClearValue(TextBlock.ForegroundProperty);
Run Code Online (Sandbox Code Playgroud)