【问题标题】:How to bind to an attached property of a subproperty of a static property如何绑定到静态属性的子属性的附加属性
【发布时间】:2011-07-28 09:20:29
【问题描述】:

我有以下代码

public static class StaticClass
{
    public static Instance Inst { get; set; }
}

public class Instance
{
    public Button Butt { get; set; }
}

我需要绑定到附加到Butt 按钮的Grid.Row 属性。我试过这个:

{Binding Source={x:Static local:StaticClass.Inst.Butt}, Path=(Grid.Row)}

但它不起作用,因为Butt 不是静态属性。通常我使用 x:Static 绑定到静态属性并将其余部分写入 Path 中,但在这种情况下 Path 包含附加属性。我不知道该怎么做。

【问题讨论】:

  • 请不要将 Button 缩写为 Butt,这让我傻笑。想想后果,比如Butt is inaccesable due to its protection level :)

标签: c# .net wpf xaml data-binding


【解决方案1】:

你需要这个,因为正如你所说,Butt 不是静态的:

{Binding Source={x:Static local:StaticClass.Inst}, Path=Butt.(Grid.Row)}

也就是说,让Butt 成为您的Path 的一部分,而不是Source 的一部分。

【讨论】:

  • 哇!没想到我可以使用这样的附加属性语法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-30
  • 1970-01-01
  • 2011-10-03
  • 2011-02-07
  • 2020-12-22
相关资源
最近更新 更多