Last active
August 1, 2023 21:51
-
-
Save worldbeater/ecfdda6960e90eecef20e878251e835c to your computer and use it in GitHub Desktop.
Boilerplate Code Encapsulation. Reactive Property. 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 ReactivePropertyViewModel | |
{ | |
public ReadOnlyReactiveProperty<string> Greeting { get; } | |
public ReactiveProperty<string> Name { get; } | |
public ReactiveCommand Clear { get; } | |
public ReactivePropertyViewModel() | |
{ | |
Clear = new ReactiveCommand(); | |
Clear.Subscribe(() => Name.Value = string.Empty); | |
Name = new ReactiveProperty<string>(string.Empty); | |
Greeting = Name | |
.Select(name => $"Hello, {name}!") | |
.ToReadOnlyReactiveProperty(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment