Пример #1
0
        private void ReloadGroupedContainerList()
        {
            var colCount                 = DesiredColumnCount;
            var flowGroupsList           = new List <FlowGroup>(FlowItemsSource.Count);
            var groupDisplayPropertyName = (FlowGroupDisplayBinding as Binding)?.Path;

            foreach (var groupContainer in FlowItemsSource)
            {
                var isAlreadyFlowGroup = groupContainer as FlowGroup;

                if (isAlreadyFlowGroup != null)
                {
                    flowGroupsList.Add(isAlreadyFlowGroup);
                }
                else
                {
                    var gr = groupContainer as IList;
                    if (gr != null)
                    {
                        var type = gr?.GetType();

                        object groupKeyValue = null;

                        if (type != null && groupDisplayPropertyName != null)
                        {
                            PropertyInfo groupDisplayProperty = type?.GetRuntimeProperty(groupDisplayPropertyName);
                            groupKeyValue = groupDisplayProperty?.GetValue(gr);
                        }

                        var flowGroup = new FlowGroup(groupKeyValue);

                        int position = -1;

                        for (int i = 0; i < gr.Count; i++)
                        {
                            if (i % colCount == 0)
                            {
                                position++;

                                flowGroup.Add(new ObservableCollection <object>()
                                {
                                    gr[i]
                                });
                            }
                            else
                            {
                                var exContItm = flowGroup[position];
                                exContItm.Add(gr[i]);
                            }
                        }

                        flowGroupsList.Add(flowGroup);
                    }
                }
            }



            ItemsSource = new ObservableCollection <FlowGroup>(flowGroupsList);
        }
        private void ReloadGroupedContainerList()
        {
            var colCount  = DesiredColumnCount;
            var groupDict = new Dictionary <object, IList <object> >();

            foreach (var item in FlowItemsSource)
            {
                var            itemGroupKey = FlowGroupGroupingKeySelector.GetProperty(item);
                IList <object> groupContainer;
                if (!groupDict.TryGetValue(itemGroupKey, out groupContainer))
                {
                    groupContainer = new List <object>();
                    groupDict.Add(itemGroupKey, groupContainer);
                }
                groupContainer.Add(item);
            }

            var flowGroupsList = new List <FlowGroup>(groupDict.Keys.Count);
            var sortedKeys     = FlowGroupKeySorting == FlowSorting.Ascending
                                ? groupDict.Keys.OrderBy(v => v) : groupDict.Keys.OrderByDescending(v => v);


            foreach (var key in sortedKeys)
            {
                var flowGroup   = new FlowGroup(key);
                var sortedItems = FlowGroupItemSorting == FlowSorting.Ascending
                                        ? groupDict[key].OrderBy(v => FlowGroupItemSortingKeySelector.GetProperty(v)).ToList()
                                        : groupDict[key].OrderByDescending(v => FlowGroupItemSortingKeySelector.GetProperty(v)).ToList();

                int position = -1;

                for (int i = 0; i < sortedItems.Count; i++)
                {
                    if (i % colCount == 0)
                    {
                        position++;

                        flowGroup.Add(new ObservableCollection <object>()
                        {
                            sortedItems[i]
                        });
                    }
                    else
                    {
                        var exContItm = flowGroup[position];
                        exContItm.Add(sortedItems[i]);
                    }
                }

                flowGroupsList.Add(flowGroup);
            }

            ItemsSource = new ObservableCollection <FlowGroup>(flowGroupsList);
        }
Пример #3
0
        private FlowObservableCollection <FlowGroup> GetGroupedContainerList()
        {
            var colCount                           = FlowDesiredColumnCount;
            var flowGroupsList                     = new List <FlowGroup>(FlowItemsSource.Count);
            var groupDisplayPropertyName           = (FlowGroupDisplayBinding as Binding)?.Path;
            var groupModelPropertyName             = (FlowGroupHeaderModelBinding as Binding)?.Path;
            var groupColumnCountPropertyName       = (FlowGroupColumnCountBinding as Binding)?.Path;
            var flowItemVisibleBindingPropertyName = (FlowItemVisibleBinding as Binding)?.Path;

            if (FlowItemsSource.Count <= 0 && FlowEmptyTemplate != null)
            {
                flowGroupsList.Add(new FlowGroup(null, null)
                {
                    new FlowEmptyModel()
                });
            }

            foreach (var groupContainer in FlowItemsSource)
            {
                if (groupContainer is FlowGroup isAlreadyFlowGroup)
                {
                    flowGroupsList.Add(isAlreadyFlowGroup);
                }
                else
                {
                    if (groupContainer is ICollection gr)
                    {
                        var type = gr?.GetType();

                        object groupKeyValue    = null;
                        object groupModelValue  = null;
                        int?   groupColumnCount = colCount;

                        if (type != null && groupDisplayPropertyName != null)
                        {
                            PropertyInfo groupDisplayProperty = type?.GetRuntimeProperty(groupDisplayPropertyName);
                            groupKeyValue = groupDisplayProperty?.GetValue(gr);
                        }

                        if (type != null && groupModelPropertyName != null)
                        {
                            PropertyInfo groupModelProperty = type?.GetRuntimeProperty(groupModelPropertyName);
                            groupModelValue = groupModelProperty?.GetValue(gr);
                        }

                        if (type != null && groupColumnCountPropertyName != null)
                        {
                            PropertyInfo groupColumnCountProperty = type?.GetRuntimeProperty(groupColumnCountPropertyName);

                            groupColumnCount = (int?)groupColumnCountProperty?.GetValue(gr);
                            groupColumnCount = groupColumnCount.GetValueOrDefault() > 0 ? groupColumnCount.Value : colCount;
                        }

                        if (groupKeyValue == null)
                        {
                            groupKeyValue = groupContainer;
                        }

                        var flowGroup = new FlowGroup(groupKeyValue, groupModelValue);

                        if (gr.Count <= 0 && FlowEmptyTemplate != null)
                        {
                            flowGroup.Add(new FlowEmptyModel());
                        }
                        else
                        {
                            int position = -1;
                            var ix       = 0;
                            var i        = 0;

                            foreach (var item in gr)
                            {
                                if (flowItemVisibleBindingPropertyName != null)
                                {
                                    var itemVisibleBindingPropertyName = item.GetType().GetRuntimeProperty(flowItemVisibleBindingPropertyName);

                                    if (itemVisibleBindingPropertyName != null)
                                    {
                                        if (!(bool)itemVisibleBindingPropertyName.GetValue(item))
                                        {
                                            i++;
                                            continue;
                                        }
                                    }
                                }

                                if (ix % groupColumnCount == 0)
                                {
                                    position++;

                                    flowGroup.Add(new FlowGroupColumn(groupColumnCount.GetValueOrDefault())
                                    {
                                        item
                                    });
                                }
                                else
                                {
                                    var exContItm = (flowGroup[position] as IList);
                                    exContItm?.Add(item);
                                }

                                ix++;
                                i++;
                            }
                        }

                        flowGroupsList.Add(flowGroup);
                    }
                }
            }

            if (FlowIsLoadingInfiniteEnabled && FlowItemsSource != null)
            {
                var sum = FlowItemsSource.Cast <object>().Sum(s => (s as IList)?.Count ?? 0);

                if (sum < FlowTotalRecords)
                {
                    flowGroupsList.LastOrDefault()?.Add(new FlowLoadingModel());
                }
            }

            return(new FlowObservableCollection <FlowGroup>(flowGroupsList));
        }