I'm not sure what I am doing wrong but I am trying to bind a class properties into an ObservableCollection so I can display added values to the rows in the DataGrid. Here is my code.
XAML:
C#:
namespace WpfApp1
{
public partial class MainWindow : Window
{
ObservableCollection<StatusLog> statusLog = new ObservableCollection<StatusLog>();
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
statusLog.Add(new StatusLog { TimeStamp = DateTime.Now.ToString(), Title="Sample Title", Message="Sample Message" });
}
}
public class StatusLog : INotifyPropertyChanged
{
private string timeStamp;
private string title;
private string message;
public string TimeStamp
{
get { return timeStamp; }
set
{
if(timeStamp != value)
{
timeStamp = value;
OnPropertyChanged("TimeStamp");
}
}
}
public string Title
{
get { return title; }
set
{
if (title != value)
{
title = value;
OnPropertyChanged("TimeStamp");
}
}
}
public string Message
{
get { return message; }
set
{
if (message != value)
{
message = value;
OnPropertyChanged("TimeStamp");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
}
If anyone can guide me to fix this, I would appreciate it.