Created
February 8, 2021 14:05
-
-
Save runceel/d860480491c359790414d79148f4338b 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 Reactive.Bindings; | |
using Reactive.Bindings.Binding; | |
using Reactive.Bindings.Extensions; | |
using System; | |
using System.Data; | |
using System.Linq; | |
using System.Reactive.Disposables; | |
using System.Reactive.Linq; | |
using System.Windows.Forms; | |
namespace WindowsFormsApp7 | |
{ | |
public partial class Form1 : Form | |
{ | |
private CompositeDisposable Disposables { get; } = new CompositeDisposable(); | |
private Form1ViewModel ViewModel { get; } | |
public Form1() | |
{ | |
InitializeComponent(); | |
ViewModel = new Form1ViewModel(); | |
FormClosed += (_, __) => Disposables.Dispose(); | |
ViewModel.Name.BindTo( | |
textBox1, | |
x => x.Text, | |
BindingMode.TwoWay, | |
targetUpdateTrigger: Observable.FromEventPattern(h => textBox1.TextChanged += h, h => textBox1.TextChanged -= h).ToUnit()) | |
.AddTo(Disposables); | |
ViewModel.UpperCase.BindTo( | |
label1, | |
x => x.Text) | |
.AddTo(Disposables); | |
} | |
} | |
public class Form1ViewModel | |
{ | |
public ReactiveProperty<string> Name { get; } | |
public ReadOnlyReactiveProperty<string> UpperCase { get; } | |
public Form1ViewModel() | |
{ | |
Name = new ReactiveProperty<string>(""); | |
UpperCase = Name.Select(x => x.ToUpper()) | |
.Delay(TimeSpan.FromSeconds(3)) | |
.ObserveOnUIDispatcher() | |
.ToReadOnlyReactiveProperty(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment