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;}
}
精彩评论