-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added simple messenger configuration for generic view models #28
- Loading branch information
1 parent
2aa9a41
commit 283f969
Showing
7 changed files
with
46 additions
and
15 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/BuildingBlocks/BuildingBlocks.Application/ViewModels/GenericViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using BuildingBlocks.Application.ViewModels.Messages; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
using CommunityToolkit.Mvvm.Messaging; | ||
|
||
namespace BuildingBlocks.Application.ViewModels; | ||
|
||
public partial class GenericItemViewModel<TModel> : ObservableObject | ||
where TModel : ObservableObject, new() | ||
{ | ||
private readonly IMessenger _messenger; | ||
|
||
[ObservableProperty] | ||
private TModel item = new(); | ||
|
||
public GenericItemViewModel(IMessenger messenger) | ||
{ | ||
_messenger = messenger; | ||
} | ||
|
||
[RelayCommand] | ||
protected virtual void Save() | ||
{ | ||
_messenger.Send(new NewGenericItemCreatedMessage<TModel>(item)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters