diff --git a/sandbox/WinFormsApp1/Form1.cs b/sandbox/WinFormsApp1/Form1.cs index fab3b7bf..d38069ad 100644 --- a/sandbox/WinFormsApp1/Form1.cs +++ b/sandbox/WinFormsApp1/Form1.cs @@ -1,37 +1,59 @@ using R3; using R3.WinForms; +using System.ComponentModel; +using System.Diagnostics; namespace WinFormsApp1; public partial class Form1 : Form { + private readonly BindableReactiveProperty rp = new(""); + public Form1() { InitializeComponent(); this.components ??= new System.ComponentModel.Container(); + + + // Bind label1.Text to rp.Value + label1.DataBindings.Add("Text", rp, "Value"); } protected override void OnCreateControl() { base.OnCreateControl(); - Observable - .EveryValueChanged( - this, - static form => form.Width) - .Subscribe(x => - { - this.Text = $"Width: {x:#,0}"; - }) - .AddTo(this.components); - - Observable - .FromEventHandler( - handler => this.button1.Click += handler, - handler => this.button1.Click -= handler) - .Delay(TimeSpan.FromSeconds(1)) - .Subscribe(_ => this.label1.Text = ObservableSystem.DefaultTimeProvider.GetLocalNow().ToString()) - .AddTo(this.components); + button1.Click += button1_Click; + + var prop = TypeDescriptor.GetProperties(rp).Find("Value", true); + Debug.WriteLine(( + prop!.ComponentType.Name, // "ReactiveProperty`1" (not Bindable) + prop.SupportsChangeEvents // false + )); + + //Observable + // .EveryValueChanged( + // this, + // static form => form.Width) + // .Subscribe(x => + // { + // this.Text = $"Width: {x:#,0}"; + // }) + // .AddTo(this.components); + + //Observable + // .FromEventHandler( + // handler => this.button1.Click += handler, + // handler => this.button1.Click -= handler) + // .Delay(TimeSpan.FromSeconds(1)) + // .Subscribe(_ => this.label1.Text = ObservableSystem.DefaultTimeProvider.GetLocalNow().ToString()) + // .AddTo(this.components); + } + + public void button1_Click(object? sender, EventArgs e) + { + // This change won't be notified to label1 + rp.Value += "X"; } } diff --git a/src/R3/BindableReactiveProperty.cs b/src/R3/BindableReactiveProperty.cs index e78a5587..01ce2bda 100644 --- a/src/R3/BindableReactiveProperty.cs +++ b/src/R3/BindableReactiveProperty.cs @@ -66,6 +66,13 @@ public BindableReactiveProperty(T value, IEqualityComparer? equalityComparer) { } + // WinForms reflection data binding require to impl Value in this type + public new T Value + { + get => base.Value; + set => base.Value = value; + } + // ToBindableReactiveProperty internal BindableReactiveProperty(Observable source, T initialValue, IEqualityComparer? equalityComparer)