0

我有以下课程,例如:

public FatherClass
{
    // This is a singleton, with instance property named Instance

    public static ChildClass PropertyName { get; set; }
}

public ChildClass
{
    public string Name { get; set; }
}

在 XAML 中使用 WPF,如何将标签绑定到此变量名称?我可以使用两个级别(即,Father.Name)来完成它,但是每次我尝试使用 3 个级别时都会出错,如示例所示。

我所做的是:

Label="{Binding Source=namespace:FatherClass.Instance.PropertyName, Path=Name}"

但这不起作用。

谢谢!

4

2 回答 2

0

Not till the point of class in a singleton(as in Question) but Property of child type in a singleton i am using. namespace:Common.DeviceModel Singleton class: ConnectionStatusManager //FatherClass of Question ChildClass : ConnectionStatus //ChildClass of Question property in that singleton: Status in VM:

namespace Common.DeviceModel
{
 public class ConnectionStatusManager : INotifyPropertyChanged
    {
      public static ConnectionStatusManager Instance...;
      public static ConnectionStatus Status...;
    }
}

XAML:

xmlns:DeviceModel="clr-namespace:Common.DeviceModel;assembly=Common"

Uses:

<DataTrigger Binding="{Binding Source={x:Static Member=DeviceModel:ConnectionStatusManager.Instance}, Path=Status}"  
                                             Value="{x:Static Member=DeviceModel:ConnectionStatus.DisConnected}">
                                                <Setter Property="IsEnabled" Value="False" />
                                            </DataTrigger>
于 2013-04-02T13:23:36.020 回答
0

只需直接绑定到静态属性:

{x:Static namespace:FatherClass.PropertyName.Name}
于 2012-05-21T20:40:51.163 回答