Hello
is both
private
and a
field.
Either of those will break a binding.
It needs to be a
public
(or
internal
)
property.
Try:
public partial class MainWindow : Window
{
private const string HelloMessage = "Hello World";
public string Hello { get { return HelloMessage; } }
public MainWindow()
{
}
}
=============
Edit: MTH - April 29, 2016
Showing binding to a property in such a way as to allow for the Label to update on changes:
XAML:
<Window>
<Label Content="{Binding Path=Hello}"/>
</Window>
C#:
using System.ComponentModel;
using System.Runtime.CompilerServices;
public partial class MainWindow : Window, INotifyPropertyChanged
{
public MainWindow()
{
InitializeComponent();
DataContext = this;
}
private string _Hello = "Select Workflow Variant:";
public string Hello
{
get { return _Hello; }
set
{
_Hello = value;
OnPropertyChanged();
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName]string propertyName = null)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
var e = new PropertyChangedEventArgs(propertyName);
handler(this, e);
}
}
#endregion
}
Now, if the
Hello
property is changed, the
Label
will be updated. Define other settable properties similarly.