Exemplo n.º 1
0
        private void SelectedItemChanged(RoutedPropertyChangedEventArgs <object> obj)
        {
            object selected = obj.NewValue;

            if (selected == null)
            {
                return;
            }

            if (selected is SimpleTreeNodeViewModel)
            {
                SimpleTreeNodeViewModel tvm = (SimpleTreeNodeViewModel)selected;
                _selectedNode = tvm;
                if (tvm.Node is Model.Feed)
                {
                    Articles = new SortableObservableCollection <Model.Article>(((Model.Feed)tvm.Node).Articles);
                }
                else if (tvm.Node is Model.Host)
                {
                    List <Model.Article> intermediate = new List <Model.Article>();
                    foreach (Model.Feed feed in ((Model.Host)tvm.Node).Feeds)
                    {
                        foreach (Model.Article a in feed.Articles)
                        {
                            intermediate.Add(a);
                        }
                    }
                    Articles = new SortableObservableCollection <Model.Article>(intermediate);
                }
                else
                {
                    if (_articles == null)
                    {
                        _articles = new SortableObservableCollection <Article>();
                    }
                    _articles.Clear();
                    foreach (Model.Host h in _allData)
                    {
                        foreach (Model.Feed feed in h.Feeds)
                        {
                            foreach (Model.Article a in feed.Articles)
                            {
                                _articles.Add(a);
                            }
                        }
                    }
                }
                SortedArticles.SortDescriptions.Clear();                                                           // Clear all
                SortedArticles.SortDescriptions.Add(new SortDescription("SortKey", ListSortDirection.Descending)); // Sort descending by "PropertyName"
                //Articles.OrderByDescending(el => el.SortKey);
            }
            RaisePropertyChanged("SortedArticles");
        }
Exemplo n.º 2
0
        private void SelectedItemChanged(RoutedPropertyChangedEventArgs<object> obj)
        {
            object selected = obj.NewValue;

            if (selected == null)
                return;

            if (selected is SimpleTreeNodeViewModel)
            {
                SimpleTreeNodeViewModel tvm = (SimpleTreeNodeViewModel)selected;
                _selectedNode = tvm;
                if (tvm.Node is Model.Feed)
                {
                    Articles = new SortableObservableCollection<Model.Article>(((Model.Feed)tvm.Node).Articles);
                }
                else if (tvm.Node is Model.Host)
                {
                    List<Model.Article> intermediate = new List<Model.Article>();
                    foreach (Model.Feed feed in ((Model.Host)tvm.Node).Feeds)
                    {
                        foreach (Model.Article a in feed.Articles)
                        {
                            intermediate.Add(a);
                        }
                    }
                    Articles = new SortableObservableCollection<Model.Article>(intermediate);
                }
                else
                {
                    if (_articles == null)
                        _articles = new SortableObservableCollection<Article>();
                    _articles.Clear();
                    foreach (Model.Host h in _allData)
                    {
                        foreach (Model.Feed feed in h.Feeds)
                        {
                            foreach (Model.Article a in feed.Articles)
                            {
                                _articles.Add(a);
                            }
                        }
                    }
                }
                SortedArticles.SortDescriptions.Clear(); // Clear all 
                SortedArticles.SortDescriptions.Add(new SortDescription("SortKey", ListSortDirection.Descending)); // Sort descending by "PropertyName"
                //Articles.OrderByDescending(el => el.SortKey);
            }
            RaisePropertyChanged("SortedArticles");
        }