Skip to content

Instantly share code, notes, and snippets.

@hilapon
Created April 26, 2022 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hilapon/738b9c4b3d0b9492aae662d8ef67a406 to your computer and use it in GitHub Desktop.
Save hilapon/738b9c4b3d0b9492aae662d8ef67a406 to your computer and use it in GitHub Desktop.
CommunityToolkit.Mvvm での ViewModel サンプル
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace MauiApp3 {
internal class MainViewModel : ObservableObject {
public RelayCommand IncrementCounterCommand { get; }
private int Counter;
public MainViewModel() {
CounterText = $"Current count: {Counter}";
IncrementCounterCommand = new RelayCommand(() => CounterText = $"Current count: {++Counter}");
}
private string _CounterText;
public string CounterText {
get => _CounterText;
set => SetProperty(ref _CounterText, value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment