made. This enables a target to automatically respond to changes. Dependency properties
already have this feature built in, but CLR properties don’t. If you want your CLR
properties to broadcast their changes, you must implement the INotifyProperty-
Changed interface.
INotifyPropertyChanged interface belongs to System.ComponentModel namespace.
using System.ComponentModel;
namespace INotifyProperyChangeShalvin
{
public class Speaker : INotifyPropertyChanged
{
private string mSpeakerName;
public string SpeakerName
{
get { return mSpeakerName; }
set
{
mSpeakerName = value;
FirePropertyChanged("SpeakerName");
}
}
public event PropertyChangedEventHandler PropertyChanged;
void FirePropertyChanged(string property)
{
if (PropertyChanged != null)
{
PropertyChanged(this,
new PropertyChangedEventArgs(property));
}
}
}
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Speaker s = new Speaker { SpeakerName = "Shalvin" };
LayoutRoot.DataContext = s;
}
<Grid x:Name="LayoutRoot" Background="White">
<TextBox Height="23" HorizontalAlignment="Left" Margin="120,47,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" Text="{Binding SpeakerName, Mode=TwoWay}" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="120,147,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" Text="{Binding SpeakerName, Mode=TwoWay}" />
</Grid>