代码之家  ›  专栏  ›  技术社区  ›  Webashlar Developers

wpf动态边界厚度绑定

  •  0
  • Webashlar Developers  · 技术社区  · 11 年前

    我有一个动态生成的边界。 我想用我的样式模型绑定它的厚度属性。

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

    这是我迄今为止所做的。这对我不起作用。
    请告诉我这个代码有什么问题。

    非常感谢。

    1 回复  |  直到 11 年前
        1
  •  0
  •   Florian Gl    11 年前

    您正在绑定到 BorderThickness 对象,具有 Path 设置为 边框厚度 。这意味着绑定将在 this.imodel.GridStyleProperties.BorderThickness.BorderThickness 这是不存在的。

    尝试

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

    或者只是

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