/// <summary> /// Factory method for creating new ListControlViewModel instances. /// </summary> /// <param name="control">Underlying list-based Control_t (of type <see cref="ListControlBase"/>) for this ControlViewModel.</param> /// <param name="referencedParameter">Parameter that the specified Control_t relates to. May be null.</param> /// <param name="mode">Data entry mode (create/amend/view).</param> /// <returns>New instance of ListControlViewModel.</returns> public static ListControlViewModel Create(ListControlBase control, IParameter referencedParameter) { ListControlViewModel controlViewModel = new ListControlViewModel(control, referencedParameter); controlViewModel._listItems = ViewModelListItemCollection.Create(controlViewModel); return(controlViewModel); }
/// <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); }
/// <summary> /// Factory method for creating new ViewModelListItemCollection instances, based on the supplied <see cref="ListControlViewModel"/>. /// </summary> /// <param name="controlViewModel">ListControlViewModel that represents the list-based control that contains the set /// of <see cref="ListItem_t"/>s that this ViewModelListItemCollection relates to.</param> /// <returns>A new ViewModelListItemCollection instance. May be an empty collection.</returns> public static ViewModelListItemCollection Create(ListControlViewModel controlViewModel) { bool controlIsRadioButtonList = controlViewModel.UnderlyingControl is RadioButtonList_t; ViewModelListItemCollection collection = new ViewModelListItemCollection(controlViewModel, controlIsRadioButtonList); // Make a unique group name for use with RadioButtonLists to ensure individual radio buttons are mutually exclusive. string groupName = Guid.NewGuid().ToString(); foreach (ListItem_t item in (controlViewModel.UnderlyingControl as ListControlBase).ListItems) { ListItemViewModel listItem = new ListItemViewModel(collection, item); if (controlIsRadioButtonList) { listItem.GroupName = groupName; } collection.Add(listItem); } return(collection); }
private ViewModelListItemCollection(ListControlViewModel controlViewModel, bool controlIsRadioButtonList) { _owningControlViewModel = controlViewModel; _controlIsRadioButtonList = controlIsRadioButtonList; }