MVVM 框架:ReactiveUI

jopen 9年前發布 | 25K 次閱讀 移動開發 ReactiveUI

ReactiveUI 是集成了 .Net 的 ReatIve 擴展的 MVVM 框架,用來創建運行與任何移動設備或者桌面平臺的優雅的可測試的用戶接口。它支持 Xamarin.iOS,Xamarin.Android,Xamarin.Mac, WPF,Windows Forms,Windows Phone 8 和 Windows Store 應用程序。

示例代碼:

public class ColorChooserThatDoesntLikeGreen : ReactiveObject
{
  //
  // Declaring a read/write property
  //
  byte _Red;
  public byte Red {
    get { return _Red; }
    set { this.RaiseAndSetIfChanged(value); }
  }
  byte _Green;
  public byte Green {
    get { return _Green; }
    set { this.RaiseAndSetIfChanged(value); }
  }
  byte _Blue;
  public byte Blue {
    get { return _Blue; }
    set { this.RaiseAndSetIfChanged(value); }
  }
  //
  // Declaring a Property that's based on an Observable
  // 
  ObservableAsPropertyHelper<Color> _Color;
  public Color Color {
    get { return _Color.Value; }
  }
  ReactiveCommand OkButton { get; protected set; }
  public ColorChooserThatDoesntLikeGreen()
  {
    var finalColor = this.WhenAny(x => x.Red, x => x.Green, x => x.Blue, 
        (r,g,b) => Color.FromRGB(r.Value, g.Value, b.Value));
    finalColor.ToProperty(this, x => x.Color, out _Color);
    // When the finalColor has full green, the Ok button is disabled
    OkButton = new ReactiveCommand(finalColor.Select(x => x.Green != 255));
  }
}

項目主頁:http://www.baiduhome.net/lib/view/home/1435844327263

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!