WPF C#如何在代码中创建THIS绑定? [英] WPF C# how to create THIS binding in code?

查看:214
本文介绍了WPF C#如何在代码中创建THIS绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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" Margin="0 -2 0 -2" X2="{Binding Path=RenderSize.Width, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}}"/>

推荐答案

Line.X2 一个依赖项属性,因此您可以按照常规方式执行此操作:

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

这篇关于WPF C#如何在代码中创建THIS绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆