Exemple #1
0
        private void OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:

                int index = e.NewStartingIndex;
                for (int i = 0; i < e.NewItems.Count; i++)
                {
                    var page = e.NewItems[i] as Page;
                    Widget.AddPage(index, page);
                    _pages.Add(new PageContainer(page, i));
                    index++;
                }

                var newPages = new List <object>();
                foreach (var pc in _pages)
                {
                    newPages.Add(pc.Page);
                }

                e.Apply(Page.Children, newPages);

                break;

            case NotifyCollectionChangedAction.Remove:

                for (int i = 0; i < e.OldItems.Count; i++)
                {
                    var page = e.OldItems[i];
                    Widget.RemovePage(page);
                    var pageContainer = _pages.FirstOrDefault(p => p.Page == page);
                    _pages.Remove(pageContainer);
                }

                var oldPages = new List <object>();
                foreach (var pc in _pages)
                {
                    oldPages.Add(pc.Page);
                }

                e.Apply(Page.Children, oldPages);
                UpdateCurrentPage();
                break;

            case NotifyCollectionChangedAction.Reset:
                Widget?.Reset();
                UpdateSource();
                break;
            }
        }