コード例 #1
0
        public NodeViewModel(NodeBase NodeModel)
        {
            InnerModel = NodeModel;

            PositionX = InnerModel.ToReactivePropertyAsSynchronized(x => x.PositionX).AddTo(container);
            PositionY = InnerModel.ToReactivePropertyAsSynchronized(x => x.PositionY).AddTo(container);
            Width     = new ReactiveProperty <double>(100);
            Height    = new ReactiveProperty <double>(60);

            Name = InnerModel.ToReactivePropertyAsSynchronized(x => x.Name).AddTo(container);

            In      = InnerModel.PrevNodes.ToReadOnlyReactiveCollection(x => new NodeInConnectionViewModel(this, x));
            InCount = new ReactiveProperty <int>(InnerModel.PrevNodes.Count);
            InnerModel.PrevNodes.CollectionChanged += (s, e) =>
            {
                InCount.Value = InnerModel.PrevNodes.Count;
                Width.Value   = InCount.Value * 50;

                IsRemoveInputConnection.Value = InCount.Value > 2;
            };

            Out = InnerModel.NextNodes.ToReadOnlyReactiveCollection(x => new NodeOutConnectionViewModel(this, x));


            FixedConnection = InnerModel.NextNodes.ToReadOnlyReactiveCollection(x => new NodeFixedConnectionViewModel(this, x));

            Result = InnerModel.ToReactivePropertyAsSynchronized(x => x.Result).AddTo(container);

            IsInputOpen = new ReactiveProperty <bool>(false);

            AddInputConnectionCommand = new ReactiveCommand().AddTo(container);
            AddInputConnectionCommand.Subscribe(() => InnerModel.ChangeConnectNodeNum(InnerModel.PrevNodes, InnerModel.PrevNodes.Count + 1));

            IsRemoveInputConnection      = new ReactiveProperty <bool>();
            RemoveInputConnectionCommand = IsRemoveInputConnection.ToReactiveCommand().AddTo(container);
            RemoveInputConnectionCommand.Subscribe(() => InnerModel.ChangeConnectNodeNum(InnerModel.PrevNodes, InnerModel.PrevNodes.Count - 1));
        }