I am recoding a WinForms app (MySQL/EF6 with many fields to update) using WPF. I am examining code required to support INotifyPropertyChanged for each field, and wondering if this is an advantage over classic code behind event handling.
I have developed a robust WinForms app in C# supporting a fairly complex data model including EF6/MySQL. As you can imagine, with many text fields, combo boxes, NumUpDowns etc, there are many event handlers for all the different fields. As I look at moving this code base to WPF and its native data binding, I have read repeatedly about the need to recode your mid level data objects to support INotifyPropertyChanged on the setters for each field in your class.
I have already coded both screen setup methods and Winforms event handlers that perform bi-directional update capability between classes and controls. Of course these would require some modification to adapt to WPF control methods and properties. I'm trying to decide whether it's worth the coding effort and ongoing maintenance required to setup INotifyPropertyChanged on each individual field that interacts with the screen, or just modify the more classic code behind event handlers. I have between 50 and 100 fields (of various types), each of which would require special coding for bi-directional binding.
Is it worth it, or am I missing something as a WPF noob?
I have many, many fields in the existing data maintenenace classes that take this form:
public class clsLot
{
// Code omitted for general error codes, enums etc.
// Here are a long list of fields which are generated by EF6 model, decorated with straightforward {get; set; }
public long idLot { get; set; }
public string LotID { get; set; }
public Nullable<long> idRecipe { get; set; }
public string PlantOrder { get; set; }
public Nullable<System.DateTime> CreateDate { get; set; }
public string Inspector { get; set; }
public string LotType { get; set; }
[... Long list omitted. For ease of maintenance when new fields are added to the database and ef6 model regened, this list is copied from ef6 gened code
// maintenance methods omitted for mapping between this class and database (save, update etc.
}
When I see examples of WPF two way binding, they say the class must support INotifyPropertyChanged, and that each field must be converted from the simpler "public string LotID {get; set;}" to something like this for each field
public class User : INotifyPropertyChanged
{
// Begin modification for each field in the class that needs to be bi-directionally mapped
private string _LotID;
public string LotID
{
get { return this._LotID; }
set
{
if(this.name != value)
{
this._LotID = value;
this.NotifyPropertyChanged("LotID");
}
}
}
// End of modification for each field
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propName)
{
if(this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
I have no problem with adding the public event, and the NotifyPropertyChanged method to existing classes. My problem is the 13x expansion in the lines of code to support INotifyPropertyChanged for each field of which I have between 50-100 fields (and can no longer be copy/pasted from autogened classes created by Ef6 Model).
Is this worth it, vs. just moving and adjusting the existing screen setup and control event handler methods I have in the Winforms app?
The core of my problem is that I am working with autogened code that takes advantage of the "public string LotID { get; set;}" syntax, that would need to be broken down into separate private fields and public properties for each field/property that is presently autogened.