MVVM
https://gyazo.com/76345c4c0a25ba0db198e5bf9189b8e1
code:ViewModel.cs
public class MyViewModel : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
private string _hello = "Hello, World!";
public string Hello
{
get => _hello;
set {
if (_hello != null) {
_hello = value;
OnPropertyChanged();
}
}
}
public void OnPropertyChanged(
=> PropertyChanged?.Invoke(
this,
new PropertyChangedEventArgs(name)
);
public ICommand OnHelloClicked { get; private set; }
public MyViewModel()
{
OnHelloClicked = new Command(() => {
this.Hello = "ようこそ";
});
}
}
code:View.xml
<Label Text="{Binding Hello}"/>
<Button Text="Click" Command="{Binding OnHelloClicked}"/>