only call notifyPropertyChanged if actually set to new value
This commit is contained in:
parent
0e46cdb514
commit
9bdcaa5eaa
@ -8,6 +8,8 @@ namespace LibationWinForms
|
|||||||
{
|
{
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
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 = "")
|
public void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
|
||||||
=> this.UIThreadAsync(() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)));
|
=> this.UIThreadAsync(() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,8 +41,11 @@ namespace LibationWinForms
|
|||||||
get => _cover;
|
get => _cover;
|
||||||
private set
|
private set
|
||||||
{
|
{
|
||||||
_cover = value;
|
if (_cover != value)
|
||||||
NotifyPropertyChanged();
|
{
|
||||||
|
_cover = value;
|
||||||
|
NotifyPropertyChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,16 +175,25 @@ namespace LibationWinForms
|
|||||||
switch (itemName)
|
switch (itemName)
|
||||||
{
|
{
|
||||||
case nameof(udi.Tags):
|
case nameof(udi.Tags):
|
||||||
Book.UserDefinedItem.Tags = udi.Tags;
|
if (Book.UserDefinedItem.Tags != udi.Tags)
|
||||||
NotifyPropertyChanged(nameof(DisplayTags));
|
{
|
||||||
|
Book.UserDefinedItem.Tags = udi.Tags;
|
||||||
|
NotifyPropertyChanged(nameof(DisplayTags));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case nameof(udi.BookStatus):
|
case nameof(udi.BookStatus):
|
||||||
Book.UserDefinedItem.BookStatus = udi.BookStatus;
|
if (Book.UserDefinedItem.BookStatus != udi.BookStatus)
|
||||||
NotifyPropertyChanged(nameof(Liberate));
|
{
|
||||||
|
Book.UserDefinedItem.BookStatus = udi.BookStatus;
|
||||||
|
NotifyPropertyChanged(nameof(Liberate));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case nameof(udi.PdfStatus):
|
case nameof(udi.PdfStatus):
|
||||||
Book.UserDefinedItem.PdfStatus = udi.PdfStatus;
|
if (Book.UserDefinedItem.PdfStatus != udi.PdfStatus)
|
||||||
NotifyPropertyChanged(nameof(Liberate));
|
{
|
||||||
|
Book.UserDefinedItem.PdfStatus = udi.PdfStatus;
|
||||||
|
NotifyPropertyChanged(nameof(Liberate));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -211,9 +223,23 @@ namespace LibationWinForms
|
|||||||
|
|
||||||
private void UpdateLiberatedStatus(bool notify = true)
|
private void UpdateLiberatedStatus(bool notify = true)
|
||||||
{
|
{
|
||||||
_bookStatus = LibraryCommands.Liberated_Status(LibraryBook.Book);
|
var changed = false;
|
||||||
_pdfStatus = LibraryCommands.Pdf_Status(LibraryBook.Book);
|
|
||||||
if (notify)
|
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));
|
NotifyPropertyChanged(nameof(Liberate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user