Ejemplo n.º 1
0
        public GeometryViewModel()
        {
            Geometries = AUTDSettings.Instance.GeometriesReactive;

            Current    = new ReactivePropertySlim <GeometrySettingReactive?>();
            AddItem    = new ReactiveCommand();
            RemoveItem = Current.Select(c => c != null).ToReactiveCommand();
            UpItem     = Current.Select(c => c != null && c.No.Value != 0).ToReactiveCommand();
            DownItem   = Current.Select(c => c != null && c.No.Value != Geometries.Count - 1).ToReactiveCommand();

            AddItem.Subscribe(_ =>
            {
                var item = new GeometrySettingReactive(Geometries.Count);
                Geometries.Add(item);
                Current.Value = item;
            });
            RemoveItem.Subscribe(_ =>
            {
                if (Current.Value == null)
                {
                    return;
                }

                var delNo = Current.Value.No.Value;
                Geometries.RemoveAt(delNo);
                ResetNo();
                Current.Value = Geometries.Count > delNo ? Geometries[delNo] : Geometries.Count > 0 ? Geometries[delNo - 1] : null;
            });
            UpItem.Subscribe(_ =>
            {
                if (Current.Value == null)
                {
                    return;
                }

                var cNo = Current.Value.No.Value;
                var up  = Geometries[cNo - 1];
                Geometries.Insert(cNo - 1, Current.Value);
                Geometries.RemoveAt(cNo);
                Geometries[cNo] = up;
                ResetNo();
                Current.Value = Geometries[cNo - 1];
            });
            DownItem.Subscribe(_ =>
            {
                if (Current.Value == null)
                {
                    return;
                }

                var cNo  = Current.Value.No.Value;
                var down = Geometries[cNo + 1];
                Geometries.RemoveAt(cNo + 1);
                Geometries.Insert(cNo + 1, Current.Value);
                Geometries[cNo] = down;
                ResetNo();
                Current.Value = Geometries[cNo + 1];
            });
        }