private void OnItemAdded(PaletteEditorTreeViewItem <T> item)
        {
            var disposables = new CompositeDisposable();

            disposables.DisposeWith(_disposables);

            // Observe item name.
            var entry = _palette.Entries[item.EntryId];

            item.Name.Skip(1).Subscribe(x =>
            {
                var oldValue = entry.Name.Value;
                _editService.Edit($"Set {typeof(T).Name} Entry Name {entry.Id}",
                                  () => entry.Name.Value = x,
                                  () => entry.Name.Value = oldValue,
                                  markAsIdOrNameDirty: true);
            }).DisposeWith(disposables);

            // Observe item values.
            void ObserveItemValue(KeyValuePair <string, ObservableProperty <T> > value)
            {
                var themeId = value.Key;

                value.Value.Skip(1).Subscribe(x =>
                {
                    var oldValue = entry.Values[themeId].Value;
                    _editService.Edit($"Set {typeof(T).Name} Entry Value {entry.Id}",
                                      () => { entry.Values[themeId].Value = x; },
                                      () => { entry.Values[themeId].Value = oldValue; });
                }).DisposeWith(disposables);
            }

            foreach (var value in item.Values)
            {
                ObserveItemValue(value);
            }

            item.Values.ObservableAdd
            .Subscribe(value =>
            {
                ObserveItemValue(new KeyValuePair <string, ObservableProperty <T> >(value.Key, value.Value));
            }).DisposeWith(disposables);

            // Observe apply button clicks.
            item.ApplyButtonClickedAsObservable.Subscribe(_ => { OpenRegisterEntryIdMenu(item.EntryId); })
            .DisposeWith(disposables);

            _perItemDisposables.Add(item.id, disposables);
        }
        public ProjectSummaryCellView()
        {
            using (this.Log().Perf($"{nameof(ProjectSummaryCellView)}: Initialize component."))
            {
                InitializeComponent();
            }

            // on iOS, waiting to bind until "WhenActivated" causes the list items to be sized
            // incorrectly. We can bind here, then add the composite disposable to the "activated" disposable
            CompositeDisposable disposables = new CompositeDisposable(
                //this
                //    .OneWayBind(ViewModel, vm => vm.Name, v => v._lblProjectName.Text),
                //this
                //    .WhenAnyValue(v => v.ViewModel.StartStatus, startStatus =>
                //    {
                //        string header = "Starts: ";
                //        switch (startStatus)
                //        {
                //            case ProjectStartStatus.ReadyNow:
                //                return $"{header}Ready Now";

                //            case ProjectStartStatus.OneToTwoWeeks:
                //                return $"{header}1 - 2 Weeks";

                //            case ProjectStartStatus.ThreeToFourWeeks:
                //                return $"{header}3 - 4 Weeks";

                //            case ProjectStartStatus.FiveOrMoreWeeks:
                //                return $"{header}5+ Weeks";

                //            default:
                //                return $"{header}Unknown";
                //        }
                //    })
                //    .BindTo(this, v => v._lblProjectDates.Text)
                );

            // handle when the view is activated
            this.WhenActivated(disposable =>
            {
                using (this.Log().Perf($"{nameof(ProjectSummaryCellView)}: Activate."))
                {
                    disposables.DisposeWith(disposable);
                }
            });
        }
Ejemplo n.º 3
0
        public MyProjectViewCell()
        {
            using (this.Log().Perf($"{nameof(MyProjectViewCell)}: Initialize component."))
            {
                InitializeComponent();
            }

            // on iOS, waiting to bind until "WhenActivated" causes the list items to be sized
            // incorrectly. We can bind here, then add the composite disposable to the "activated" disposable
            CompositeDisposable disposables = new CompositeDisposable(
                //this
                //    .OneWayBind(ViewModel, vm => vm.Project.Name, v => v._lblProjectName.Text),
                this
                .OneWayBind(ViewModel, vm => vm.Project.Description, v => v._lblProjectDescription.Text)
                //this
                //    .WhenAnyValue(v => v.ViewModel.Project.StartStatus, startStatus =>
                //    {
                //        string header = "Starts: ";
                //        switch (startStatus)
                //        {
                //            case ProjectStartStatus.ReadyNow:
                //                return $"{header}Ready Now";

                //            case ProjectStartStatus.OneToTwoWeeks:
                //                return $"{header}1 - 2 Weeks";

                //            case ProjectStartStatus.ThreeToFourWeeks:
                //                return $"{header}3 - 4 Weeks";

                //            case ProjectStartStatus.FiveOrMoreWeeks:
                //                return $"{header}5+ Weeks";

                //            default:
                //                return $"{header}Unknown";
                //        }
                //    })
                //    .BindTo(this, v => v._lblDateRange.Text)
                );

            // handle when the view is activated
            this.WhenActivated(disposable =>
            {
                using (this.Log().Perf($"{nameof(MyProjectViewCell)}: Activate."))
                {
                    disposables.DisposeWith(disposable);

                    // handle settings that don't affect display here
                    _tgrEdit
                    .Events()
                    .Tapped
                    .ToSignal()
                    .InvokeCommand(this, v => v.ViewModel.Edit)
                    .DisposeWith(disposable);

                    _tgrClose
                    .Events()
                    .Tapped
                    .ToSignal()
                    .InvokeCommand(this, v => v.ViewModel.Close)
                    .DisposeWith(disposable);

                    _tgrDelete
                    .Events()
                    .Tapped
                    .ToSignal()
                    .InvokeCommand(this, v => v.ViewModel.Delete)
                    .DisposeWith(disposable);
                }
            });
        }