public ExpandoOperationViewModel() { AddInputCommand = new RequeryCommand( () => Input.Add(new ConnectorViewModel()), () => Input.Count < MaxInput); RemoveInputCommand = new RequeryCommand( () => Input.RemoveAt(Input.Count - 1), () => Input.Count > MinInput); }
public StateMachineViewModel() { PendingTransition = new TransitionViewModel(); Runner = new StateMachineRunnerViewModel(this); Blackboard = new BlackboardViewModel() { Actions = new NodifyObservableCollection <BlackboardItemReferenceViewModel>(BlackboardDescriptor.GetAvailableItems <IBlackboardAction>()), Conditions = new NodifyObservableCollection <BlackboardItemReferenceViewModel>(BlackboardDescriptor.GetAvailableItems <IBlackboardCondition>()) }; // public INodifyObservableCollection<T> WhenAdded(Action<T> added) // INodifyObservableCollection<T>, Action<T> 임으로 T는 WhenAdded 의부모 속성을 가지므로 파라미터 하나짜리 익명함수의 경우 해당 파라미터는 부모의 객체 타입이다. // Source 의경우는 TransitionViewModel 객체의 StateViewModel 이다. // public NodifyObservableCollection<StateViewModel> Transitions { get; } = new NodifyObservableCollection<StateViewModel>(); // 초기화 구문 같은데... Transitions.WhenAdded(c => c.Source.Transitions.Add(c.Target)) .WhenRemoved(c => c.Source.Transitions.Remove(c.Target)) .WhenCleared(c => c.ForEach(i => { i.Source.Transitions.Clear(); i.Target.Transitions.Clear(); })); States.WhenAdded(x => x.Graph = this) .WhenRemoved(x => DisconnectState(x)) .WhenCleared(x => { Transitions.Clear(); OnCreateDefaultNodes(); }); OnCreateDefaultKeys(); // 여기서 노드와 arrow 가 생성됨. OnCreateDefaultNodes(); // RequeryCommand ??? RenameStateCommand = new RequeryCommand(() => SelectedStates[0].IsRenaming = true, () => SelectedStates.Count == 1 && SelectedStates[0].IsEditable); DisconnectStateCommand = new RequeryCommand <StateViewModel>(x => DisconnectState(x), x => !IsRunning && x.Transitions.Count > 0); DisconnectSelectionCommand = new RequeryCommand(() => SelectedStates.ForEach(x => DisconnectState(x)), () => !IsRunning && SelectedStates.Count > 0 && Transitions.Count > 0); DeleteSelectionCommand = new RequeryCommand(() => SelectedStates.ToList().ForEach(x => x.IsEditable.Then(() => States.Remove(x))), () => !IsRunning && (SelectedStates.Count > 1 || (SelectedStates.Count == 1 && SelectedStates[0].IsEditable))); AddStateCommand = new RequeryCommand <Point>(p => States.Add(new StateViewModel { Name = "New State", IsRenaming = true, Location = p, ActionReference = Blackboard.Actions.Count > 0 ? Blackboard.Actions[0] : null }), p => !IsRunning); CreateTransitionCommand = new DelegateCommand <(object Source, object?Target)>(s => Transitions.Add(new TransitionViewModel { Source = (StateViewModel)s.Source, Target = (StateViewModel)s.Target ! }), s => !IsRunning && s.Source is StateViewModel source && s.Target is StateViewModel target && target != s.Source && target != States[0] && !source.Transitions.Contains(s.Target));
public CalculatorInputOperationViewModel() { AddOutputCommand = new RequeryCommand( () => Output.Add(new ConnectorViewModel { Title = $"In {Output.Count}" }), () => Output.Count < 10); RemoveOutputCommand = new RequeryCommand( () => Output.RemoveAt(Output.Count - 1), () => Output.Count > 1); Output.Add(new ConnectorViewModel { Title = $"In {Output.Count}" }); }
public ApplicationViewModel() { _calculators.Push(new CalculatorViewModel()); BackCommand = new RequeryCommand(() => { _calculators.Pop(); OnPropertyChanged(nameof(Current)); OnPropertyChanged(nameof(IsCalculatorOpen)); }, () => _calculators.Count > 1); OpenCalculatorCommand = new DelegateCommand <CalculatorViewModel>(calculator => { _calculators.Push(calculator); OnPropertyChanged(nameof(Current)); OnPropertyChanged(nameof(IsCalculatorOpen)); }); }