Example #1
0
        public Picker <TPickerItem> Items(IEnumerable <TPickerItem> items)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            items = items.ToList();

            if (!items.Any())
            {
                throw new ArgumentException(nameof(items));
            }

            if (PickerItems.Any(pickerItem => items.Any(item => pickerItem.Name.Equals(item.Name))))
            {
                throw new ArgumentException("Can not add duplicate items");
            }

            _pickerItems.AddRange(items);

            foreach (var item in items)
            {
                if (item.IsSelected)
                {
                    CreateSelection(item);
                }
            }

            return(this);
        }
Example #2
0
        private void AddGroupedItems(IEnumerable <T> items, ObservableList <IComponent> observableList, bool isGrid)
        {
            observableList.Clear();

            if (items is object)
            {
                items = items.ToList();

                if (items.Any())
                {
                    foreach (var groupedItems in items.GroupBy(item => item.Group).OrderBy(g => g.Key, _groupComparer))
                    {
                        var header = new GroupedItemsHeader(groupedItems.Key, _groupedItemHeaderGenerator);
                        if (isGrid)
                        {
                            header.GridColumn(1, -1);
                        }

                        observableList.Add(header);
                        observableList.AddRange(groupedItems.Select(t => t.Render()));
                    }
                }
            }
        }