WPF C # how to create an IT binding in code?

I wonder how to create this binding, since the Line.X2 property is NOT dependent !: (

<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}}}"/>
+3
source share
1 answer

Line.X2 is a dependency property , so you can do it the usual way:

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

Source: https://habr.com/ru/post/1736929/


All Articles