2015-07-21 83 views
0

我有一個動態生成的邊框。 我想綁定它的厚度屬性,我的風格模型。wpf動態邊框厚度綁定

Border db = new Border();               
Binding borderthickness = new Binding(); 
borderthickness.Source = this.imodel.GridStyleProperties.BorderThickness; 
borderthickness.Path = new PropertyPath("BorderThickness"); 
BindingOperations.SetBinding(db, Border.BorderThicknessProperty, borderthickness); 

這就是我迄今爲止所做的。它不適合我。
請告訴我這段代碼有什麼問題。

謝謝

回答

0

您綁定到一個BorderThickness對象,具有Path設置爲BorderThickness。這意味着綁定將顯示在this.imodel.GridStyleProperties.BorderThickness.BorderThickness不存在。

嘗試

borderthickness.Source = this.imodel.GridStyleProperties; 
borderthickness.Path = new PropertyPath("BorderThickness"); 

或只是

borderthickness.Source = this.imodel.GridStyleProperties.BorderThickness; 
+0

優秀的..現在工作正常..謝謝你這麼多。 –