user3502966
user3502966

Reputation: 59

Notify Property Changed not working

this my xml code

<TextBlock Grid.Column="0" Tag="{Binding id,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Text="{Binding Name,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>

this is my model

public string _Name;
public string Name
{
    get { return _Name; }
    set { _Name = value; RaisePropertyChanged("Name"); }
}      

when i set value to these two propertie ie. to id and Name

but its not notifying to Name ...

Upvotes: 1

Views: 6050

Answers (1)

Chubosaurus Software
Chubosaurus Software

Reputation: 8161

Simple Databinding Example with Updates. You can use this as a reference to get you started :)

public partial class MainWindow : Window, INotifyPropertyChanged
{
    // implement the INotify
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(String propertyName)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (null != handler)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    private string _mytext;
    public String MyText
    {
        get { return _mytext;  }
        set { _mytext = value; NotifyPropertyChanged("MyText"); }
    }

    public MainWindow()
    {
        InitializeComponent();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        this.DataContext = this;             // set the datacontext to itself :)
        MyText = "Change Me";
    }
}

<TextBlock Text="{Binding MyText}" Foreground="White" Background="Black"></TextBlock>

Upvotes: 3

Related Questions