text box value won't updated using data bind
(new to WPF) in order to prevent long discussion in the comment section
I'm asking it again.
I have text box which bind to an object. When I'm changing the object
value the text box text value won't change. I read all most each
discussion exist here about this and didn't figure it out.
XAML:
<TextBox Height="36" HorizontalAlignment="Left" Margin="174,0,0,400"
Name="txtStudenName" VerticalAlignment="Bottom" Width="240"
IsEnabled="False" >
<TextBox.Text>
<Binding NotifyOnSourceUpdated="True"
Path="firstName"
UpdateSourceTrigger="PropertyChanged" >
</Binding>
</TextBox.Text>
codebehyond
public partial class MainWindow : Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private student _selectedStudent;
public student selectedStudent // This is the object
{
get { return _selectedStudent; }
set
{
if (value != _selectedStudent)
{
_selectedStudent = value;
OnPropertyChanged("_selectedStudent");
}
}
}
public MainWindow()
{
InitializeComponent();
selectedStudent = clsLoadStudent();
this.DataContext = selectedStudent; // Here I use the object
as a datacontext.
}
private void dgStudents_SelectionChanged(object sender,
SelectionChangedEventArgs e)
{
selectedStudent = new student();
selectedStudent = (student)dgStudents.SelectedItem;
}
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null) // if there is any subscribers
PropertyChanged(this, new
PropertyChangedEventArgs(propertyName));
}
}
I have been told to implement OnPropertyChanged... I did.. I think..
No comments:
Post a Comment