protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); System.Diagnostics.Debug.Assert(_disposables == null); System.Diagnostics.Debug.Assert(ViewModel == null); _disposables = new CompositeDisposable(); ViewModel = new ViewModel(); _delegateSpinnerView = FindViewById <Spinner>(Resource.Id.delegate_spinner_view); this.OneWayBind(ViewModel, vm => vm.Data, v => v._delegateSpinnerView.Adapter, data => new SpinnerAdapter(this, data)) .AddTo(_disposables); this.WhenAnyValue(v => v.ViewModel.SelectedIndex) .Subscribe(idx => _delegateSpinnerView.SetSelection(idx, true)) .AddTo(_disposables); Observable.FromEvent <EventHandler <AdapterView.ItemSelectedEventArgs>, AdapterView.ItemSelectedEventArgs>( f => (s, e) => f(e), h => _delegateSpinnerView.ItemSelected += h, h => _delegateSpinnerView.ItemSelected -= h) .Subscribe(e => ViewModel.SelectedIndex = e.Position) .AddTo(_disposables); _canvasView = FindViewById <UGCanvasView>(Resource.Id.canvas_view); this.OneWayBind(ViewModel, vm => vm.Delegate, v => v._canvasView.Delegate) .AddTo(_disposables); }
public override void ViewDidLoad() { base.ViewDidLoad(); var frame = View.Frame; frame.Height -= delegatePopUpButton.VisibleRect().Height; #if USE_LAYER View.WantsLayer = true; var layer = new UGCanvasCALayer(); layer.Frame = View.Frame; View.Layer.AddSublayer(layer); _layer = layer; #else var canvas = new UGCanvasView(frame) { AutoresizingMask = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable, }; View.AddSubview(canvas); _canvas = canvas; #endif ViewModel = new ViewModel(); this.WhenAnyValue(v => v.ViewModel.Data) .Subscribe(data => { delegatePopUpButton.RemoveAllItems(); delegatePopUpButton.AddItems(data); }) .AddTo(_disposables); this.WhenAnyValue(v => v.ViewModel.SelectedIndex) .Subscribe(idx => delegatePopUpButton.SelectItem(idx)) .AddTo(_disposables); Observable.FromEvent <EventHandler, EventArgs>( f => (s, e) => f(e), h => delegatePopUpButton.Activated += h, h => delegatePopUpButton.Activated -= h) .Subscribe(_ => ViewModel.SelectedIndex = (int)delegatePopUpButton.IndexOfSelectedItem) .AddTo(_disposables); #if USE_LAYER this.OneWayBind(ViewModel, vm => vm.Delegate, v => v._layer.CanvasDelegate) .AddTo(_disposables); #else this.OneWayBind(ViewModel, vm => vm.Delegate, v => v._canvas.Delegate) .AddTo(_disposables); #endif }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { #if USE_LAYER if (_layer != null) { _layer.RemoveFromSuperLayer(); _layer.Dispose(); _layer = null; } #else if (_canvas != null) { _canvas.Dispose(); _canvas = null; } #endif } }