Skip to content

Instantly share code, notes, and snippets.

@hilapon
Last active April 25, 2022 07:39
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/8e9459fc40eea7fe6a768ed5cdbad199 to your computer and use it in GitHub Desktop.
Save hilapon/8e9459fc40eea7fe6a768ed5cdbad199 to your computer and use it in GitHub Desktop.
ビューモデルにカウンタ更新用のコマンドを追加した
using System.ComponentModel;
using System.Windows.Input;
namespace MauiApp1 {
internal class MainViewModel : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
public ICommand CounterCommand { private set; get; }
private int Counter;
#region コンストラクタ
public MainViewModel() {
CounterText = $"Current count: 0";
CounterCommand = new Command(execute: () => CounterText = $"Current count: {++Counter}");
}
#endregion
#region プロパティ
string _CounterText;
public string CounterText {
get => _CounterText;
private set {
if (_CounterText == value) return;
_CounterText = value;
OnPropertyChanged(nameof(CounterText));
}
}
#endregion
protected virtual void OnPropertyChanged(string propertyName) {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment