PDA

View Full Version : WPF DataBinding



chakkaradeep
September 22nd, 2007, 02:28 AM
Hi,

I just started exploring WPF Data Binding. Though I know to implement a simple data binding, but I want to understand what actually the INotifyPropertyChanged's event handler - PropertyChangedEventHandler code does.



protected void OnPropertyChanged(String name)
{
PropertyChangedEventHandler handler = PropertyChanged;

if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
I want to know more what happens in the red text in the above code

I would be happy if anyone could explain me :)

Thanks

chakkaradeep
September 22nd, 2007, 02:46 AM
Ok, just removed the unwanted extra variable in the OnPropertyChanged

So, now its looks simple,



protected void OnPropertyChanged(String name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}

chakkaradeep
September 22nd, 2007, 03:04 AM
Ok, to make things complex,

Here is my sample. I just have a TextBox and Label - both bound to a FriendsName Class which implements INotifyPropertyChanged

I have set the UpdateSourceTrigger to PropertyChanged and thus whenever I type something in the TextBox, my Label gets updated then and there.

Now, What I want to do is, I want to have a Button, say Update and when I click that , the data should update the source and thus result the change in the Label. So, its like, after I complete typing in the TextBox, click on the Update Button, the Label should not be updated with the value :D

Hope I am clear :(

I would be really happy if someone help me :)

Thanks,