Browse Source

Use relay command form of RemoveFromParentList

pull/333/head
Ionite 1 year ago
parent
commit
76fcc1cb15
No known key found for this signature in database
  1. 2
      StabilityMatrix.Avalonia/Controls/StackExpander.axaml
  2. 30
      StabilityMatrix.Avalonia/ViewModels/Base/ViewModelBase.cs

2
StabilityMatrix.Avalonia/Controls/StackExpander.axaml

@ -52,7 +52,7 @@
Text="{Binding Title}"/>
<Button
IsVisible="{Binding IsEditEnabled}"
Command="{Binding RemoveFromParentList}"
Command="{Binding RemoveFromParentListCommand}"
Classes="transparent-red"
Grid.Column="3"
Padding="10,4"

30
StabilityMatrix.Avalonia/ViewModels/Base/ViewModelBase.cs

@ -2,14 +2,15 @@
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using StabilityMatrix.Avalonia.Models;
namespace StabilityMatrix.Avalonia.ViewModels.Base;
public class ViewModelBase : ObservableValidator, IRemovableListItem
public partial class ViewModelBase : ObservableValidator, IRemovableListItem
{
private WeakEventManager? parentListRemoveRequestedEventManager;
public event EventHandler ParentListRemoveRequested
{
add
@ -20,24 +21,23 @@ public class ViewModelBase : ObservableValidator, IRemovableListItem
remove => parentListRemoveRequestedEventManager?.RemoveEventHandler(value);
}
protected void RemoveFromParentList() => parentListRemoveRequestedEventManager?.RaiseEvent(
this, EventArgs.Empty, nameof(ParentListRemoveRequested));
public virtual void OnLoaded()
{
}
[RelayCommand]
protected void RemoveFromParentList() =>
parentListRemoveRequestedEventManager?.RaiseEvent(
this,
EventArgs.Empty,
nameof(ParentListRemoveRequested)
);
public virtual void OnLoaded() { }
public virtual Task OnLoadedAsync()
{
return Task.CompletedTask;
}
public virtual void OnUnloaded()
{
}
public virtual void OnUnloaded() { }
public virtual Task OnUnloadedAsync()
{
return Task.CompletedTask;

Loading…
Cancel
Save