开发者

WPF C# how to create THIS binding in code?

开发者 https://www.devze.com 2022-12-23 09:57 出处:网络
I wonder, how to create this binding, since Line.X2 IS NOT dependency property! :( <Line Y1=\"0\" X1=\"0\" Y2=\"0\" Stroke=\"Blue\" StrokeThickness=\"3开发者_C百科\" Margin=\"0 -2 0 -2\" X2=\"{Bin

I wonder, how to create this binding, since Line.X2 IS NOT dependency property! :(

<Line Y1="0" X1="0" Y2="0" Stroke="Blue" StrokeThickness="3开发者_C百科" Margin="0 -2 0 -2" X2="{Binding Path=RenderSize.Width, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}}"/>


Line.X2 is a dependency property so you can do this in the normal way:

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

精彩评论

暂无评论...
验证码 换一张
取 消