开发者

How to bind with XAML

I want to bind a property of a class to a label content.

public partial class MainWindow : Window
{
   public MyClass singletonInst = MyClass.Instance;
   //...
} 

public clas开发者_开发问答s MyClass
{
    public String MyValue
    {
        get { return "i'm the value"; }
    }
    //...
}

In My MainWindow.Xaml.cs I have my Window Name="DefaultWindow" and for my label I have..

<Label Content="{Binding ElementName=DefaultWindow, Path=singletonInst.MyValue}" ...

But it doesn't work. Any Suggestions?


You can only bind to properties and not fields.

public MyClass SingletonInst
{
    get { return MyClass.Instance;}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜