代码之家  ›  专栏  ›  技术社区  ›  0xDEAD BEEF

wpfc#如何在代码中创建此绑定?

  •  3
  • 0xDEAD BEEF  · 技术社区  · 16 年前

    我想知道如何创建这个绑定,因为Line.X2不是依赖属性!:(

    <Line Y1="0" X1="0" Y2="0" Stroke="Blue" StrokeThickness="3" Margin="0 -2 0 -2" X2="{Binding Path=RenderSize.Width, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}}"/>
    
    1 回复  |  直到 16 年前
        1
  •  5
  •   itowlson    16 年前

    Line.X2 is a dependency property 所以你可以用正常的方法:

    myLine.SetBinding(Line.X2Property,
      new Binding("RenderSize.Width")
      {
        RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(StackPanel), 1)
      });