[入门]c# ReactiveUI 监控控件信息 替代控件原有事件

//NuGet包
  <ItemGroup>
    <PackageReference Include="ReactiveUI" Version="16.2.6" />
    <PackageReference Include="ReactiveUI.Events.Winforms" Version="15.1.1" />
    <PackageReference Include="ReactiveUI.Fody" Version="16.2.6" />
    <PackageReference Include="ReactiveUI.WinForms" Version="16.2.6" />
  </ItemGroup>
//文本框Text变化时候执行操作
            this.WhenAnyValue(s => s.textBox1.Text)
                .Subscribe((t) => Debug.WriteLine(t));
//全局变量
public ReactiveCommand<MouseEventArgs, System.Reactive.Unit> ClickCmd;


public Form1()
{
    InitializeComponent();

    //事件  传参   窗体其他控件操作!
    ClickCmd = ReactiveCommand.Create<MouseEventArgs>(a =>
                                                      {
        this.textBox1.Focus();
        this.textBox1.Text = "123456789";
        this.button1.Focus();
    });
    this.button1.Events().Click.InvokeCommand(this, x => x.ClickCmd);
}
posted @ 2021-10-19 23:43  ToLing·  阅读(458)  评论(0编辑  收藏  举报