Ejemplo n.º 1
0
        private void NextButton_Click(object sender, RoutedEventArgs e)
        {
            if (IsTransitionOn)
            {
                return;
            }
            IsTransitionOn = true;

            PageIndex += 1;
            HandleButtonVisibility();
            this.CurrentPage = this.slidingPages[PageIndex];
            ChangePage(p => Transitor.SlideLeft(p));
        }
Ejemplo n.º 2
0
        private void PrevButton_Click(object sender, RoutedEventArgs e)
        {
            //Skip Prev Transition
            if (IsTransitionOn)
            {
                return;
            }
            IsTransitionOn = true;

            PageIndex -= 1;
            HandleButtonVisibility();
            this.CurrentPage = this.slidingPages[PageIndex];
            ChangePage(p => Transitor.SlideRight(p));
        }
Ejemplo n.º 3
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            var width  = this.ActualWidth;
            var height = this.ActualHeight;

            int hCount = (int)width / 300;
            int vCount = (int)height / 150;

            ItemsPerPage = hCount * vCount;

            ItemSourceValueChange(ItemSource);

            HandleButtonVisibility();
            ChangePage(p => Transitor.SlideRight(p));
        }
Ejemplo n.º 4
0
        private void ItemSourceValueChange(IEnumerable <SlidingItem> items)
        {
            if (items != null)
            {
                decimal pageFraction = (decimal)items.Count() / ItemsPerPage;
                int     pageCount    = (int)Math.Ceiling(pageFraction);

                if (PageCount <= 0 && pageCount != PageCount)
                {
                    PageCount = pageCount;
                    for (int i = 1; i <= PageCount; i++)
                    {
                        var pageItems = items.Skip((i - 1) * ItemsPerPage).Take(ItemsPerPage).ToList();
                        slidingPages.Add(new SlidingPage
                        {
                            Index = i - 1,
                            Items = pageItems
                        });
                    }
                    CurrentPage = slidingPages[PageIndex];
                }
                else if (pageCount > PageCount)
                {
                    PageCount = pageCount;
                    slidingPages.Add(new SlidingPage
                    {
                        Index = PageCount - 1,
                        Items = items.Skip((PageCount - 1) * ItemsPerPage).Take(ItemsPerPage).ToList()
                    });
                    HandleButtonVisibility();
                }
                else
                {
                    PageCount = pageCount;
                    bool isRemoved = false;
                    foreach (var page in slidingPages)
                    {
                        var removed = page.Items.Except(items.Select(x => x)).FirstOrDefault();
                        if (removed != null)
                        {
                            isRemoved = true;
                            slidingPages.Clear();

                            for (int i = 1; i <= PageCount; i++)
                            {
                                var pageItems = items.Skip((i - 1) * ItemsPerPage).Take(ItemsPerPage).ToList();
                                slidingPages.Add(new SlidingPage
                                {
                                    Index = i - 1,
                                    Items = pageItems
                                });
                            }
                            PageIndex   = PageIndex >= PageCount ? PageIndex - 1 : PageIndex;
                            CurrentPage = slidingPages[PageIndex];
                            HandleButtonVisibility();
                            Transitor.RefreshPage(CurrentPage);
                            break;
                        }
                    }

                    if (!isRemoved)
                    {
                        var slidingPage = slidingPages[PageCount - 1];
                        slidingPage.Items = items.Skip((PageCount - 1) * ItemsPerPage).Take(ItemsPerPage).ToList();
                        CurrentPage       = slidingPages[PageIndex];
                    }
                }
            }
        }