/// <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);
        }
Beispiel #2
0
        /// <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);
        }
 /// <summary>
 /// Initializes a new instance of <see cref="ListItemViewModel"/>, specifying the ViewModelListItemCollection
 /// that this ListItemViewModel belongs to and the underlying <see cref="ListItem_t"/>.
 /// </summary>
 /// <param name="owningCollection">Collection of ListItemViewModels, which corresponds to the set of ListItems
 /// for a control.</param>
 /// <param name="listItem">ListItem_t that this ListItemViewModel is responsible for.</param>
 public ListItemViewModel(ViewModelListItemCollection owningCollection, ListItem_t listItem)
 {
     _owningCollection   = owningCollection;
     _underlyingListItem = listItem;
 }