Пример #1
0
        private void SearchData(object sender, TextChangedEventArgs e)
        {
            /*
             * var sourceItems = DomainfinalList;
             * ObservableCollection<DomainAndStoresDetails> searchedList = new ObservableCollection<DomainAndStoresDetails>();
             * try
             * {
             *  if (string.IsNullOrWhiteSpace(e.NewTextValue) && e.NewTextValue == "" && e.NewTextValue == null)
             *  {
             *      listview.ItemsSource = DomainfinalList;
             *  }
             *  else
             *  {
             *      foreach (var item in sourceItems)
             *      {
             *          var data = item.Where(X => (X.Name.ToLower()).Contains(e.NewTextValue.ToLower())).Any();
             *          if (data == true)
             *          {
             *              var dataGroup = new DomainAndStoresDetails { DomainName = item.DomainName, DomainUniqueKey = item.DomainUniqueKey, ImageSource = item != null ? item.ImageSource : "", StartColor = item.StartColor, EndColor = item.EndColor };
             *              var storeItemsObtained = item.Where(X => (X.Name.ToLower()).Contains(e.NewTextValue.ToLower())).ToList();
             *              foreach (var storeItems in storeItemsObtained)
             *              {
             *                  dataGroup.Add(storeItems);
             *              }
             *              searchedList.Add(dataGroup);
             *          }
             *      }
             *      listview.ItemsSource = searchedList;
             *  }
             * }
             * catch (Exception ex)
             * {
             *  var msg = ex.Message;
             * }
             */

            try
            {
                var searchValue = (e.NewTextValue).ToLower();
                if (string.IsNullOrWhiteSpace(e.NewTextValue) && e.NewTextValue == "" && e.NewTextValue == null)
                {
                    listQuizTopics.ItemsSource = quizGroup;
                }
                else
                {
                    ObservableCollection <QuizGroup> listViewSearchedItems = new ObservableCollection <QuizGroup>();
                    foreach (var sourceGroupItem in quizGroup)
                    {
                        var groupItemPresent = sourceGroupItem.Where(X => X.TopicName.ToLower().Contains(searchValue)).Any();
                        if (groupItemPresent)
                        {
                            var groupItem = new QuizGroup {
                                GroupName = sourceGroupItem.GroupName
                            };
                            var topicsWithSearchValue = sourceGroupItem.Where(X => X.TopicName.ToLower().Contains(searchValue)).ToList();
                            foreach (var topicItem in topicsWithSearchValue)
                            {
                                groupItem.Add(topicItem);
                            }
                            listViewSearchedItems.Add(groupItem);
                        }
                    }
                    listQuizTopics.ItemsSource = listViewSearchedItems;
                }
            }
            catch (Exception ex)
            {
                PrintLog.PublishLog(ex);
            }
        }
Пример #2
0
        public void GetListViewData()
        {
            List <QuizTopic> quizTopics;

            try
            {
                quizTopics = new List <QuizTopic>()
                {
                    new QuizTopic()
                    {
                        GroupName = "Group0", TopicName = "Topic01"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group0", TopicName = "Topic02"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group0", TopicName = "Topic03"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group0", TopicName = "Topic04"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group0", TopicName = "Topic05"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group0", TopicName = "Topic06"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group1", TopicName = "Topic11"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group1", TopicName = "Topic12"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group1", TopicName = "Topic13"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group1", TopicName = "Topic14"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group1", TopicName = "Topic15"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group1", TopicName = "Topic16"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group2", TopicName = "Topic21"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group2", TopicName = "Topic22"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group2", TopicName = "Topic23"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group2", TopicName = "Topic24"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group2", TopicName = "Topic25"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group2", TopicName = "Topic26"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group3", TopicName = "Topic31"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group3", TopicName = "Topic32"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group3", TopicName = "Topic33"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group3", TopicName = "Topic34"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group3", TopicName = "Topic35"
                    },
                    new QuizTopic()
                    {
                        GroupName = "Group3", TopicName = "Topic36"
                    }
                };

                List <string> groupNames = quizTopics.Select(X => X.GroupName).Distinct().OrderBy(s => s).ToList();
                quizGroup = new ObservableCollection <QuizGroup>();
                foreach (var selectedGroup in groupNames)
                {
                    var selectedTopics = quizTopics.Where(X => X.GroupName == selectedGroup).ToList();
                    var _quizGroup     = new QuizGroup()
                    {
                        GroupName = selectedGroup
                    };
                    foreach (var topics in selectedTopics)
                    {
                        _quizGroup.Add(topics);
                    }
                    quizGroup.Add(_quizGroup);
                }

                listQuizTopics.ItemsSource = quizGroup;
            }
            catch (Exception ex)
            {
                PrintLog.PublishLog(ex);
            }
        }