-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dialog: use mvvm pattern for sound command dialog
- Loading branch information
Showing
3 changed files
with
61 additions
and
30 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
SimpleTwitchEmoteSounds/ViewModels/NewSoundCommandDialogViewModel.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,37 @@ | ||
using System; | ||
using Avalonia.Input; | ||
using CommunityToolkit.Mvvm.ComponentModel; | ||
using CommunityToolkit.Mvvm.Input; | ||
|
||
namespace SimpleTwitchEmoteSounds.ViewModels; | ||
|
||
public partial class NewSoundCommandDialogViewModel : ObservableObject | ||
{ | ||
[ObservableProperty] private string _name = string.Empty; | ||
[ObservableProperty] private string _category = string.Empty; | ||
|
||
[RelayCommand] | ||
private void Ok() | ||
{ | ||
CloseRequested?.Invoke(this, new NewSoundCommandResult(Name, Category)); | ||
} | ||
|
||
[RelayCommand] | ||
private void Cancel() | ||
{ | ||
CloseRequested?.Invoke(this, null); | ||
} | ||
|
||
[RelayCommand] | ||
private void KeyDown(KeyEventArgs e) | ||
{ | ||
if (e.Key == Key.Enter) | ||
{ | ||
Ok(); | ||
} | ||
} | ||
|
||
public event EventHandler<NewSoundCommandResult?>? CloseRequested; | ||
} | ||
|
||
public record NewSoundCommandResult(string Name, string Category); |
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