public ViewModelStateRuleCollection(ControlViewModel owningControl, StateRuleCollection stateRules) { _owningControl = owningControl; foreach (StateRule_t stateRule in stateRules) { StateRuleViewModel stateRuleViewModel = new StateRuleViewModel(owningControl, stateRule); Add(stateRuleViewModel); } }
/// <summary> /// Factory method for creating new ControlViewModel instances. /// </summary> /// <param name="underlyingStrategy"><see cref="Strategy_t"/> that this ControlViewModel's <see cref="Control_t"/> is a member of.</param> /// <param name="control">Underlying Control_t for this ControlViewModel.</param> /// <returns>New ControlViewModel instance.</returns> public static ControlViewModel Create(Strategy_t underlyingStrategy, Control_t control, IInitialFixValueProvider initialValueProvider) { IParameter referencedParameter = null; if (control.ParameterRef != null) { referencedParameter = underlyingStrategy.Parameters[control.ParameterRef]; if (referencedParameter == null) { throw ThrowHelper.New <ReferencedObjectNotFoundException>(ErrorMessages.UnresolvedParameterRefError, control.ParameterRef); } } ControlViewModel controlViewModel; #if !NET_40 // This is to workaround a bug in .NET Framework 3.5 where it is possible for more than one radio button in a // group to be checked at a time. if (control is RadioButton_t) { controlViewModel = new RadioButtonViewModel(control as RadioButton_t, referencedParameter); } else #endif if (control is ListControlBase) { controlViewModel = ListControlViewModel.Create(control as ListControlBase, referencedParameter); } else if (InvalidatableControlViewModel.IsInvalidatable(control)) { controlViewModel = InvalidatableControlViewModel.Create(control, referencedParameter); } else { controlViewModel = new ControlViewModel(control, referencedParameter); } controlViewModel._stateRules = new ViewModelStateRuleCollection(controlViewModel, control.StateRules); controlViewModel._fixFieldValues = new FixFieldValueProvider(initialValueProvider, underlyingStrategy.Parameters); return(controlViewModel); }
public StateRuleViewModel(ControlViewModel owningControl, StateRule_t stateRule) { _owningControlViewModel = owningControl; _underlyingStateRule = stateRule; if (stateRule.Edit != null) { _edit = new EditViewModel(stateRule.Edit); } else if (stateRule.EditRef != null) { _edit = new EditViewModel(stateRule.EditRef); } else { // TODO: Proper exception please. throw new Exception("Neither Edit nor EditRef set!"); } }
// TODO: Provide a means to unbind (probably through dispose) void IBindable <ViewModelControlCollection> .Bind(ViewModelControlCollection controls) { if (_edits != null && _edits.Count > 0) { (_edits as IBindable <ViewModelControlCollection>).Bind(controls); } else { if (!string.IsNullOrEmpty(_underlyingEdit.Field)) { if (controls.Contains(_underlyingEdit.Field)) { ControlViewModel targetControl = controls[_underlyingEdit.Field]; (targetControl as INotifyValueChanged).ValueChanged += new EventHandler <ValueChangedEventArgs>(OnFieldValueChanged); } else { throw ThrowHelper.New <ReferencedObjectNotFoundException>(this, ErrorMessages.EditRefFieldControlNotFound, _underlyingEdit.Field, "Field"); } } if (!string.IsNullOrEmpty(_underlyingEdit.Field2)) { if (controls.Contains(_underlyingEdit.Field2)) { ControlViewModel targetControl = controls[_underlyingEdit.Field2]; (targetControl as INotifyValueChanged).ValueChanged += new EventHandler <ValueChangedEventArgs>(OnField2ValueChanged); } else { throw ThrowHelper.New <ReferencedObjectNotFoundException>(this, ErrorMessages.EditRefFieldControlNotFound, _underlyingEdit.Field2, "Field2"); } } } }