【问题标题】:WPF C# how to create THIS binding in code?WPF C#如何在代码中创建这个绑定?
【发布时间】:2011-01-27 12:27:26
【问题描述】:

我想知道如何创建这个绑定,因为 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}}}"/>

【问题讨论】:

  • 尝试在 C# 代码隐藏中设置它?

标签: wpf binding properties dependencies


【解决方案1】:

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

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

【讨论】:

  • 谢谢!我忘了添加属性哟X2!我的错!
猜你喜欢
  • 1970-01-01
  • 2016-09-08
  • 2011-07-03
  • 2015-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-10
相关资源
最近更新 更多