Disabled DeleteButton when no coin is selected.
This commit is contained in:
1 parent
298e6d8294
commit
c97db12f8a
1 file changed
+6
-4
@@ -43,12 +43,14 @@ public class MainWindowViewModel : ViewModelBase
|
|||||||
_pcgsClient = new PcgsClient("eAb8gS0I2XAvT_5gJeiGJaglMia1Tk-oB4kJUK6kuafyrny_S61vIJY-Ikl4nCQM67wrdxzUqLVWTV2kBSxD3d5XNBHxHnYBhcSS6dOPug0hZaF3qAv56df3gYSzOGh9Tif5y0eP3Iw0LrqKDr1Hj-dk6SV6GKog2IIqCPQhhHH8FMTWBTYO-_O8cx7qLdM5GM8KlTsic6g3VRUhM8EA_4OO04dCfmNLGhqINRl3jGZ0Q4ziI8fng2bVWsIyteqiPzUn10rIQ3-OPpqVZG_DxeOmOejj4GzbUNyqUOajy-nr5rYY");
|
_pcgsClient = new PcgsClient("eAb8gS0I2XAvT_5gJeiGJaglMia1Tk-oB4kJUK6kuafyrny_S61vIJY-Ikl4nCQM67wrdxzUqLVWTV2kBSxD3d5XNBHxHnYBhcSS6dOPug0hZaF3qAv56df3gYSzOGh9Tif5y0eP3Iw0LrqKDr1Hj-dk6SV6GKog2IIqCPQhhHH8FMTWBTYO-_O8cx7qLdM5GM8KlTsic6g3VRUhM8EA_4OO04dCfmNLGhqINRl3jGZ0Q4ziI8fng2bVWsIyteqiPzUn10rIQ3-OPpqVZG_DxeOmOejj4GzbUNyqUOajy-nr5rYY");
|
||||||
|
|
||||||
ShowDeleteWindow = new Interaction<DeleteWindowViewModel, bool>();
|
ShowDeleteWindow = new Interaction<DeleteWindowViewModel, bool>();
|
||||||
|
var deleteEnabled = this.WhenAnyValue(x => x.SelectedCoin)
|
||||||
|
.Select(x => x != null);
|
||||||
DeleteCommand = ReactiveCommand.CreateFromTask(async () =>
|
DeleteCommand = ReactiveCommand.CreateFromTask(async () =>
|
||||||
{
|
{
|
||||||
var deleteViewModel = new DeleteWindowViewModel();
|
var deleteViewModel = new DeleteWindowViewModel();
|
||||||
var result = await ShowDeleteWindow.Handle(deleteViewModel);
|
var result = await ShowDeleteWindow.Handle(deleteViewModel);
|
||||||
if (result && SelectedCoin != null) CoinCollection.Remove(SelectedCoin);
|
if (result) CoinCollection.Remove(SelectedCoin); // possible null deref - ignored due to button being disabled.
|
||||||
});
|
}, deleteEnabled);
|
||||||
|
|
||||||
// Subscribe to SidebarContent.OkCommand, which is an IObservable<(int, string, int)>
|
// Subscribe to SidebarContent.OkCommand, which is an IObservable<(int, string, int)>
|
||||||
// This is the same as the above, but with a different syntax.
|
// This is the same as the above, but with a different syntax.
|
||||||
@@ -61,9 +63,9 @@ public class MainWindowViewModel : ViewModelBase
|
|||||||
TotalValue += newCoin.Quantity * newCoin.PriceGuideValue;
|
TotalValue += newCoin.Quantity * newCoin.PriceGuideValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Change TotalValue anytime SelectedCoin.TotalPrice changes. This does work properly with the DeleteCommand.
|
// Change TotalValue anytime SelectedCoin.TotalPrice changes.
|
||||||
|
// Possible null deref - ignored due to null values summing to 0.
|
||||||
this.WhenAnyValue(x => x.SelectedCoin.TotalPrice)
|
this.WhenAnyValue(x => x.SelectedCoin.TotalPrice)
|
||||||
.Where(x => x != null)
|
|
||||||
.Subscribe(_ => TotalValue = CoinCollection.Sum(x => x.TotalPrice) );
|
.Subscribe(_ => TotalValue = CoinCollection.Sum(x => x.TotalPrice) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user