This is functioning. The model wouldn't need to implement INotifyPropertyChanged with this. It feels like too much.
This commit is contained in:
@@ -1,12 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MVPLearning.BaseLibrary
|
||||
{
|
||||
public class BaseForm : Form
|
||||
public class BaseForm : Form, INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
protected virtual void RaisePropertyChanged([CallerMemberName] string propertyName = "")
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = "")
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(storage, value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
storage = value;
|
||||
RaisePropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,20 +56,20 @@ namespace MVPLearning.RecordKeeping.SermonFiler
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
//HashCode hash = new();
|
||||
//hash.Add(Seid);
|
||||
//hash.Add(Title);
|
||||
//hash.Add(Scripture);
|
||||
//hash.Add(When);
|
||||
//hash.Add(Subject);
|
||||
//hash.Add(Minister);
|
||||
//hash.Add(Where);
|
||||
//hash.Add(Ref_No);
|
||||
//hash.Add(Notes);
|
||||
//hash.Add(Filename);
|
||||
//hash.Add(Web);
|
||||
//return hash.ToHashCode();
|
||||
return base.GetHashCode();
|
||||
HashCode hash = new();
|
||||
hash.Add(Seid);
|
||||
hash.Add(Title);
|
||||
hash.Add(Scripture);
|
||||
hash.Add(When);
|
||||
hash.Add(Subject);
|
||||
hash.Add(Minister);
|
||||
hash.Add(Where);
|
||||
hash.Add(Ref_No);
|
||||
hash.Add(Notes);
|
||||
hash.Add(Filename);
|
||||
hash.Add(Web);
|
||||
return hash.ToHashCode();
|
||||
//return base.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ namespace MVPLearning.RecordKeeping.SermonFiler
|
||||
_model = new() { Title = "Constructor value"};
|
||||
_model.PropertyChanged += ModelChanged;
|
||||
BindControls();
|
||||
TextBoxTitle.DataBindings.Clear();
|
||||
TextBoxTitle.DataBindings.Add("Text", _model, "Title");
|
||||
//TextBoxFileName.TextChanged += TextBoxFileName_TextChanged ;
|
||||
//ButtonLaunch.Enabled = !string.IsNullOrEmpty(_model.Filename);
|
||||
}
|
||||
@@ -40,23 +38,54 @@ namespace MVPLearning.RecordKeeping.SermonFiler
|
||||
_model.Filename = model.Filename;
|
||||
_model.Web = model.Web;
|
||||
//EnableButtonLaunch();
|
||||
|
||||
Title = _model.Title;
|
||||
Scripture = _model.Scripture;
|
||||
When = _model.When;
|
||||
Subject = _model.Subject;
|
||||
Minister = _model.Minister;
|
||||
Where = _model.Where;
|
||||
Ref_No = _model.Ref_No;
|
||||
Notes = _model.Notes;
|
||||
Filename = _model.Filename;
|
||||
Web = _model.Web;
|
||||
}
|
||||
public void BindControls()
|
||||
{
|
||||
TextBoxTitle.Bind(_model, nameof(_model.Title));
|
||||
TextBoxTitle.Bind(this, nameof(Title));
|
||||
TextBoxTitle.GotFocus += TextBoxTitle_GotFocus;
|
||||
TextBoxTitle.LostFocus += TextBoxTitle_LostFocus;
|
||||
TextBoxScriptureReference.Bind(_model, nameof(_model.Scripture));
|
||||
DatePickerWhenDelivered.Bind(_model, nameof(_model.When));
|
||||
TextBoxSubject.Bind(_model, nameof(_model.Subject));
|
||||
TextBoxWhoDelivered.Bind(_model, nameof(_model.Minister));
|
||||
TextBoxWhereDelivered.Bind(_model, nameof(_model.Where));
|
||||
TextBoxReferenceNumber.Bind(_model, nameof(_model.Ref_No));
|
||||
TextBoxNotes.Bind(_model, nameof(_model.Notes));
|
||||
TextBoxFileName.Bind(_model, nameof(_model.Filename));
|
||||
TextBoxWebUrl.Bind(_model, nameof(_model.Web));
|
||||
TextBoxScriptureReference.Bind(this, nameof(Scripture));
|
||||
DatePickerWhenDelivered.Bind(this, nameof(When));
|
||||
TextBoxSubject.Bind(this, nameof(Subject));
|
||||
TextBoxWhoDelivered.Bind(this, nameof(Minister));
|
||||
TextBoxWhereDelivered.Bind(this, nameof(Where));
|
||||
TextBoxReferenceNumber.Bind(this, nameof(Ref_No));
|
||||
TextBoxNotes.Bind(this, nameof(Notes));
|
||||
TextBoxFileName.Bind(this, nameof(Filename));
|
||||
TextBoxWebUrl.Bind(this, nameof(Web));
|
||||
|
||||
}
|
||||
private string _title = string.Empty;
|
||||
public string Title { get => _title; set { if (SetProperty(ref _title, value)) { _model.Title = value; } } }
|
||||
private string _scripture = string.Empty;
|
||||
public string Scripture { get => _scripture; set { if (SetProperty(ref _scripture, value)) { _model.Scripture= value; } } }
|
||||
private DateTime? _when = null;
|
||||
public DateTime? When { get => _when; set { if (SetProperty(ref _when, value)) { _model.When = value; } } }
|
||||
private string _subject = string.Empty;
|
||||
public string Subject { get => _subject; set { if (SetProperty(ref _subject, value)) { _model.Subject = value; } } }
|
||||
private string _minister = string.Empty;
|
||||
public string Minister { get => _minister; set { if (SetProperty(ref _minister, value)) { _model.Minister = value; } } }
|
||||
private string _where = string.Empty;
|
||||
public string Where { get => _where; set { if (SetProperty(ref _where, value)) { _model.Where = value; } } }
|
||||
private string _ref_no = string.Empty;
|
||||
public string Ref_No { get => _ref_no; set { if (SetProperty(ref _ref_no, value)) { _model.Ref_No = value; } } }
|
||||
private string _notes = string.Empty;
|
||||
public string Notes { get => _notes; set { if (SetProperty(ref _notes, value)) { _model.Notes = value; } } }
|
||||
private string _filename = string.Empty;
|
||||
public string Filename { get => _filename; set { if (SetProperty(ref _filename, value)) { _model.Filename = value; } } }
|
||||
private string _web = string.Empty;
|
||||
public string Web { get => _web; set { if (SetProperty(ref _web, value)) { _model.Web = value; } } }
|
||||
private void TextBoxTitle_LostFocus(object? sender, EventArgs e)
|
||||
{
|
||||
WarnTitleIsEmpty();
|
||||
|
||||
Reference in New Issue
Block a user