【问题标题】:What's the code-behind equivalent of {Binding}?{Binding} 的代码隐藏等价物是什么?
【发布时间】:2012-05-24 06:41:31
【问题描述】:

此代码的代码隐藏等效项是什么?

<SomeControl SomeProperty="{Binding}"/>

(如果我想在 SomeControl 的代码隐藏中而不是在消费者的 XAML 中执行此操作。)

也就是说,我如何构造一个 Binding 对象,以便直接绑定到当前对象的 DataContext,而不是绑定到某个属性?

【问题讨论】:

  • 不完全。我知道该怎么做。我不知道直接绑定到 DataContext 的语法。
  • 没有尝试过,但由于绑定的构造函数只是采用路径。试试新的 Binding(".")。

标签: c# silverlight silverlight-3.0


【解决方案1】:

既然{Binding} 只是{Binding Path=.} 的一个快捷方式,它应该就这么简单

SomeControl.SetBinding(SomeControl.SomeProperty, new Binding("."));

【讨论】:

    【解决方案2】:

    看看BindingOperations.SetBinding

    BindingOperations.SetBinding(myControl, MyControlClass.Property, new Binding(...));
    

    【讨论】:

      猜你喜欢
      • 2012-06-03
      • 1970-01-01
      • 2019-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-15
      • 2021-12-26
      相关资源
      最近更新 更多