简体   繁体   中英

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 class 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;}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM