Skip to main content
 首页 » 编程设计

c#之如何绑定(bind)到静态属性的子属性的附加属性

2024年02月23日13lexus

我有以下代码

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

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

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

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

请您参考如下方法:

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

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

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