wpf文本块绑定无法正常工作

时间:2012-11-14 15:40:59

标签: c# wpf

我是WPF编程的新手,如果这是一个简单的问题,请原谅我。

我的Mainwindow.xaml设置如下:

<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>

再向下我有一个文本块:

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

在我的课上我有:

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

当我更改StatusMessage时,文本块不会更新。我在哪里弄错了?

1 个答案:

答案 0 :(得分:6)

绑定不正确 -

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

应该是 -

<TextBlock Text="{Binding Path=StatusMessage}"
相关问题