only call notifyPropertyChanged if actually set to new value

This commit is contained in:
Robert McRackan 2022-05-13 16:30:46 -04:00
parent 0e46cdb514
commit 9bdcaa5eaa
2 changed files with 39 additions and 11 deletions

View File

@ -8,6 +8,8 @@ namespace LibationWinForms
{
public event PropertyChangedEventHandler PropertyChanged;
// per standard INotifyPropertyChanged pattern:
// https://docs.microsoft.com/en-us/dotnet/desktop/wpf/data/how-to-implement-property-change-notification
public void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
=> this.UIThreadAsync(() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)));
}

View File

@ -41,8 +41,11 @@ namespace LibationWinForms
get => _cover;
private set
{
_cover = value;
NotifyPropertyChanged();
if (_cover != value)
{
_cover = value;
NotifyPropertyChanged();
}
}
}
@ -172,16 +175,25 @@ namespace LibationWinForms
switch (itemName)
{
case nameof(udi.Tags):
Book.UserDefinedItem.Tags = udi.Tags;
NotifyPropertyChanged(nameof(DisplayTags));
if (Book.UserDefinedItem.Tags != udi.Tags)
{
Book.UserDefinedItem.Tags = udi.Tags;
NotifyPropertyChanged(nameof(DisplayTags));
}
break;
case nameof(udi.BookStatus):
Book.UserDefinedItem.BookStatus = udi.BookStatus;
NotifyPropertyChanged(nameof(Liberate));
if (Book.UserDefinedItem.BookStatus != udi.BookStatus)
{
Book.UserDefinedItem.BookStatus = udi.BookStatus;
NotifyPropertyChanged(nameof(Liberate));
}
break;
case nameof(udi.PdfStatus):
Book.UserDefinedItem.PdfStatus = udi.PdfStatus;
NotifyPropertyChanged(nameof(Liberate));
if (Book.UserDefinedItem.PdfStatus != udi.PdfStatus)
{
Book.UserDefinedItem.PdfStatus = udi.PdfStatus;
NotifyPropertyChanged(nameof(Liberate));
}
break;
}
}
@ -211,9 +223,23 @@ namespace LibationWinForms
private void UpdateLiberatedStatus(bool notify = true)
{
_bookStatus = LibraryCommands.Liberated_Status(LibraryBook.Book);
_pdfStatus = LibraryCommands.Pdf_Status(LibraryBook.Book);
if (notify)
var changed = false;
var newBookStatus = LibraryCommands.Liberated_Status(LibraryBook.Book);
if (_bookStatus != newBookStatus)
{
_bookStatus = newBookStatus;
changed = true;
}
var newPdfStatus = LibraryCommands.Pdf_Status(LibraryBook.Book);
if (_pdfStatus != newPdfStatus)
{
_pdfStatus = newPdfStatus;
changed = true;
}
if (changed && notify)
NotifyPropertyChanged(nameof(Liberate));
}