bep
bep

Reputation: 752

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?

Upvotes: 0

Views: 207

Answers (1)

evanb
evanb

Reputation: 3111

You can only bind to properties and not fields.

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

Upvotes: 2

Related Questions