Last active
April 25, 2022 07:39
-
-
Save hilapon/8e9459fc40eea7fe6a768ed5cdbad199 to your computer and use it in GitHub Desktop.
ビューモデルにカウンタ更新用のコマンドを追加した
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
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