37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
namespace LD_SysInfo;
|
|
|
|
public partial class MainWindowViewModel : ObservableObject
|
|
{
|
|
//This is using the source generators from CommunityToolkit.Mvvm to generate a RelayCommand
|
|
//See: https://learn.microsoft.com/dotnet/communitytoolkit/mvvm/generators/observableproperty
|
|
//and: https://learn.microsoft.com/windows/communitytoolkit/mvvm/observableobject
|
|
[ObservableProperty]
|
|
[NotifyCanExecuteChangedFor(nameof(IncrementCountCommand))]
|
|
private int _count;
|
|
|
|
public MainWindowViewModel()
|
|
{
|
|
|
|
}
|
|
|
|
//This is using the source generators from CommunityToolkit.Mvvm to generate a RelayCommand
|
|
//See: https://learn.microsoft.com/dotnet/communitytoolkit/mvvm/generators/relaycommand
|
|
//and: https://learn.microsoft.com/windows/communitytoolkit/mvvm/relaycommand
|
|
[RelayCommand(CanExecute = nameof(CanIncrementCount))]
|
|
private void IncrementCount()
|
|
{
|
|
Count++;
|
|
}
|
|
|
|
private bool CanIncrementCount() => Count < 5;
|
|
|
|
[RelayCommand]
|
|
private void ClearCount()
|
|
{
|
|
Count = 0;
|
|
}
|
|
}
|