简体   繁体   English

wpf动态边框厚度绑定

[英]wpf dynamic border thickness binding

I have a border generated dynamically. 我有一个动态生成的边框。 I want to bind thickness property of it, with my style model. 我想将其厚度属性与样式模型绑定在一起。

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

This is what I have done so far. 到目前为止,这是我所做的。 Its not working for me. 它对我不起作用。
Please suggest me what is wrong with this code. 请建议我这段代码有什么问题。

Thank you 谢谢

You are binding to a BorderThickness object, with Path set to BorderThickness . 您将绑定到BorderThickness对象,并且Path设置为BorderThickness That means the binding will look in this.imodel.GridStyleProperties.BorderThickness.BorderThickness which doesn't exist. 这意味着绑定将在不存在的this.imodel.GridStyleProperties.BorderThickness.BorderThickness中查找。

Try 尝试

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

or just 要不就

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM