Last active
August 1, 2023 21:50
-
-
Save worldbeater/9504b98f1c86606c9c05a00689588d7d to your computer and use it in GitHub Desktop.
Observables. Shorter Getters And Setters. ReactiveUI. See: https://medium.com/@worldbeater/reactive-mvvm-for-net-platform-175dc69cfc82
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
public class ReactiveViewModel : ReactiveObject | |
{ | |
public ReactiveViewModel() | |
{ | |
Clear = ReactiveCommand.Create(() => { Name = string.Empty; }); | |
this.WhenAnyValue(x => x.Name) | |
.Select(name => $"Hello, {name}!") | |
.ToProperty(this, x => x.Greeting, out greeting); | |
} | |
public ReactiveCommand<Unit, Unit> Clear { get; } | |
private readonly ObservableAsPropertyHelper<string> greeting; | |
public string Greeting => greeting.Value; | |
private string name = string.Empty; | |
public string Name | |
{ | |
get => name; | |
set => this.RaiseAndSetIfChanged(ref name, value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment