Esempio n. 1
0
        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
        }
Esempio n. 2
0
        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
            }
        }