亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

RX:如何將 IObservable<object> 綁定到屬性 (ReactiveUI)

RX:如何將 IObservable<object> 綁定到屬性 (ReactiveUI)

C#
LEATH 2022-12-24 14:27:53
我上課MyClient時有IObservable<IStatus>( Client.StatusStream())?,F在我想結合ReactiveXand ReactiveUI。但是文檔沒有提供任何如何一起使用它們的示例。到目前為止,我已經嘗試了一些擴展方法 (fe .ToProperty),但它們不起作用。public partial class MainWindow : ReactiveWindow<AppViewModel>{    public MainWindow()    {        InitializeComponent();        ViewModel = App.Container.GetInstance<AppViewModel>();        this.WhenActivated(r =>            {                this.OneWayBind(ViewModel, viewModel => viewModel.Status.AoiStatus, view => view.StatusTxtbl.Text).DisposeWith(r);                this.OneWayBind(ViewModel, viewModel => viewModel.Status.OperationMode, view => view.OpModeTxtbl.Text).DisposeWith(r);                this.OneWayBind(ViewModel, viewModel => viewModel.Status.TestPlan, view => view.TestplanTxtbl.Text).DisposeWith(r);            });    }    private async void ButtonGetStatus_OnClick(object sender, RoutedEventArgs e)    {        // the manual mode to get the actual status information        var status = await ViewModel.Client.GetStatusAsync();        ViewModel.Status = status;    }}public class AppViewModel : ReactiveObject{    private IStatus _Status;    public IStatus Status    {        get => _Status;        set => this.RaiseAndSetIfChanged(ref _Status, value);    }    public MyClient Client { get; }    public AppViewModel(MyClient client)    {        Client = client;        // automatically pushes every new status information        Client.StatusStream(); // <- How to get the data out there?    }}
查看完整描述

1 回答

?
呼喚遠方

TA貢獻1856條經驗 獲得超11個贊

定義Status輸出屬性

public class AppViewModel : ReactiveObject

{

    private readonly ObservableAsPropertyHelper<IStatus> _status;

    public string Status => _status.Value;


    public MyClient Client { get; }


    public AppViewModel(MyClient client)

    {

        Client = client;

        Client.StatusStream().ToProperty(this, x => x.Status, out _status);

    }

}


查看完整回答
反對 回復 2022-12-24
  • 1 回答
  • 0 關注
  • 86 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號