Exemplo n.º 1
0
        public StateViewModel(StateSave state, StateSaveCategory category, IElement element)
        {
            this.category = category;
            this.element  = element;

            BackingData = state;

            Variables = new ObservableCollection <StateVariableViewModel>();
            Name      = state?.Name;

            for (int i = 0; i < element.CustomVariables.Count; i++)
            {
                var variable = element.CustomVariables[i];

                // see if there is a value for this variable
                var instruction =
                    state?.InstructionSaves.FirstOrDefault(item => item.Member == variable.Name);

                var viewModel = new StateVariableViewModel();
                viewModel.VariableName     = variable.Name;
                viewModel.Value            = instruction?.Value;
                viewModel.DefaultValue     = element.GetCustomVariable(variable.Name)?.DefaultValue;
                viewModel.PropertyChanged += HandleStateVariablePropertyChanged;
                viewModel.HasState         = state != null;
                this.Variables.Add(viewModel);
            }
        }
Exemplo n.º 2
0
        private void HandleStateViewModelValueChanged(StateViewModel stateViewModel, StateVariableViewModel stateVariableViewModel)
        {
            var value          = stateVariableViewModel.Value;
            var element        = GlueState.Self.CurrentElement;
            var customVariable = element.GetCustomVariable(stateVariableViewModel.VariableName);

            ApplyValueToModel(value, stateViewModel, stateViewModel.BackingData, customVariable);
        }