0

I am new to WPF programming, so forgive me if this is a simple issue.

I have my Mainwindow.xaml set up like so:

<Window x:Class="GNMAwpf.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:GNMAwpf"
    Title="Uploader" 
    Height="353" Width="342" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">

<Window.DataContext>
    <local:GinniNet x:Name="g" />
</Window.DataContext>

Further down I have a textblock:

<TextBlock Text="{Binding Path=StatusText}" Grid.ColumnSpan="2" MinWidth="150"></TextBlock>

In my class i have :

class GinniNet : INotifyPropertyChanged
{

    public event PropertyChangedEventHandler PropertyChanged;
    private string _statusMessage;
    public string StatusMessage
    {
        get
        {
            return _statusMessage;
        }
        set
        {
            _statusMessage = value;
            OnPropertyChanged("StatusMessage");
        }
    }
    public GinniNet()
    {
        StatusMessage = "Ready";
    } 
    private void OnPropertyChanged(string property)
    {

        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(property));
    }
}

When I change StatusMessage The textblock does not update ever. Where am i making my mistake?

4

1 回答 1

6

绑定不正确 -

<TextBlock Text="{Binding Path=StatusText}"/>

它应该是 -

<TextBlock Text="{Binding Path=StatusMessage}"
于 2012-11-14T15:44:40.227 回答