2010-01-20 95 views

回答

2

使用SetBinding方法:

ccDetails.SetBinding(ContentControl.ContentProperty, new Binding()) 
+0

我很害怕使用它,我认为Binding只有在现有的DataContexed控件下的Xaml中初始化时才继承DataContext,我只是认为它是动态的,谢谢。 – Shimmy 2010-01-20 03:14:01

0

这个工作对我来说:

Dim dc = ccDetails.GetValue(ContentControl.DataContextProperty) 
ccDetails.SetValue(ContentControl.ContentProperty, dc) 

很想听到更好的想法。

+1

这是一次性的setValue,没有约束力的声明。我想你会发现当INotifyPropertyChanged事件触发时这不会更新。 – bendewey 2010-01-20 02:52:34

+0

它为我工作,即使是财产变化,我做了一个浅的不可靠的测试,我想我会用itowlson的答案,谢谢。 – Shimmy 2010-01-20 03:12:44

0

我相信这将是与此类似:

public void SetupManualBinding() 
{ 
    var cc = new ContentControl(); 
    var binding = new Binding(); 
    cc.SetBinding(ContentControl.ContentProperty, binding); 
} 
+0

不会,那会将内容的*值*设置为绑定对象。它不会绑定ContentProperty。 – itowlson 2010-01-20 02:54:37

+0

@itowlson谢谢,更新为绑定,我的错。 – bendewey 2010-01-20 02:55:19

相关问题