如何绑定到静态属性的子属性的附加属性

时间:2011-07-28 09:20:30

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

我有以下代码

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

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

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

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

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

1 个答案:

答案 0 :(得分:4)

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

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

也就是说,将Butt作为Path的一部分,而不是Source的一部分。