New __ARCHITECTURE NOTES.txt incl. MVVM comments
This commit is contained in:
parent
ff4b2d2ecc
commit
d1779726e6
@ -5,6 +5,7 @@ VisualStudioVersion = 17.0.31903.59
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Solution Items", "_Solution Items", "{03C8835F-936C-4AF7-87AE-FF92BDBE8B9B}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Solution Items", "_Solution Items", "{03C8835F-936C-4AF7-87AE-FF92BDBE8B9B}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
__ARCHITECTURE NOTES.txt = __ARCHITECTURE NOTES.txt
|
||||||
__README - COLLABORATORS.txt = __README - COLLABORATORS.txt
|
__README - COLLABORATORS.txt = __README - COLLABORATORS.txt
|
||||||
__TODO.txt = __TODO.txt
|
__TODO.txt = __TODO.txt
|
||||||
_DB_NOTES.txt = _DB_NOTES.txt
|
_DB_NOTES.txt = _DB_NOTES.txt
|
||||||
|
|||||||
@ -6,6 +6,7 @@ namespace LibationWinForms
|
|||||||
{
|
{
|
||||||
public abstract class AsyncNotifyPropertyChanged : SynchronizeInvoker, INotifyPropertyChanged
|
public abstract class AsyncNotifyPropertyChanged : SynchronizeInvoker, INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
|
// see also notes in Libation/Source/__ARCHITECTURE NOTES.txt :: MVVM
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
// per standard INotifyPropertyChanged pattern:
|
// per standard INotifyPropertyChanged pattern:
|
||||||
|
|||||||
@ -231,6 +231,7 @@ namespace LibationWinForms
|
|||||||
{
|
{
|
||||||
var entry = new GridEntry(libraryBook);
|
var entry = new GridEntry(libraryBook);
|
||||||
entry.Committed += reapplyFilter;
|
entry.Committed += reapplyFilter;
|
||||||
|
// see also notes in Libation/Source/__ARCHITECTURE NOTES.txt :: MVVM
|
||||||
entry.LibraryBookUpdated += (sender, _) => _dataGridView.InvalidateRow(_dataGridView.GetRowIdOfBoundItem((GridEntry)sender));
|
entry.LibraryBookUpdated += (sender, _) => _dataGridView.InvalidateRow(_dataGridView.GetRowIdOfBoundItem((GridEntry)sender));
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|||||||
14
Source/__ARCHITECTURE NOTES.txt
Normal file
14
Source/__ARCHITECTURE NOTES.txt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
MVVM
|
||||||
|
====
|
||||||
|
Libation is not strictly MVVM. It's not strictly anything. There are however efforts at moving some major components toward this pattern.
|
||||||
|
|
||||||
|
Primary View: ProductsGrid
|
||||||
|
Primary View Model: GridEntry
|
||||||
|
|
||||||
|
see also: https://docs.microsoft.com/en-us/dotnet/desktop/winforms/controls/raise-change-notifications--bindingsource
|
||||||
|
BindingSource + INotifyPropertyChanged + DataGridView is the backbone of our implementation. The SortableBindingList (BindingList/BindingSource) automatically subscribes to each entry's NotifyPropertyChanged -- which is why our AsyncNotifyPropertyChanged.NotifyPropertyChanged is needed even though none of our code calls it.
|
||||||
|
|
||||||
|
- Adding or removing an entry to/from this BindingSource automatically updates the UI. No additional code needed.
|
||||||
|
- Updating a field updates the UI via calling NotifyPropertyChanged.
|
||||||
|
|
||||||
|
We break the pattern with updating the book inside of GridEntry. To really follow MVVM, iterate through every bound ("binded"?) field name and call NotifyPropertyChanged. It's much more convenient, quicker, and less error prone to make an exception to MVVM via GridEntry.LibraryBookUpdated => InvalidateRow. The downside is that the view has to wire this up. If we change where in the code we can update the book inside of GridEntry, this dependency will also need to be duplicated in the new place
|
||||||
Loading…
x
Reference in New Issue
Block a user