private void OnRightMouseDown(object sender, MouseButtonEventArgs args)
        {
            BookPage bp0 = GetTemplateChild("sheet0") as BookPage;
            BookPage bp1 = GetTemplateChild("sheet1") as BookPage;

            Canvas.SetZIndex((bp0 as BookPage), 0);
            Canvas.SetZIndex((bp1 as BookPage), 1);
        }
        public void AnimateToNextPage(bool fromTop, int duration)
        {
            if (CurrentSheetIndex + 1 <= GetItemsCount() / 2)
            {
                BookPage bp1 = GetTemplateChild("sheet1") as BookPage;

                if (bp1 == null)
                {
                    return;
                }
                Canvas.SetZIndex((bp1 as BookPage), 1);
                bp1.AutoTurnPage(fromTop ? CornerOrigin.TopLeft : CornerOrigin.BottomLeft, duration);
            }
        }
        public void AnimateToPreviousPage()
        {
            if (CurrentSheetIndex > 0)
            {
                BookPage bp1 = GetTemplateChild("sheet1") as BookPage;

                if ((bp1 == null))
                {
                    return;
                }

                Canvas.SetZIndex((bp1 as BookPage), 0);
                CurrentSheetIndex--;
            }
        }
        public void AnimateToPreviousPage(bool fromTop, int duration)
        {
            if (CurrentSheetIndex > 0)
            {
                BookPage bp0 = GetTemplateChild("sheet0") as BookPage;
                BookPage bp1 = GetTemplateChild("sheet1") as BookPage;

                if ((bp0 == null) || (bp1 == null))
                {
                    return;
                }

                Canvas.SetZIndex((bp1 as BookPage), 0);
                Canvas.SetZIndex((bp0 as BookPage), 1);
                bp0.AutoTurnPage(fromTop ? CornerOrigin.TopLeft : CornerOrigin.BottomLeft, duration);
            }
        }
        private void OnLoaded(object sender, RoutedEventArgs args)
        {
            BookPage bp0 = GetTemplateChild("sheet0") as BookPage;
            BookPage bp1 = GetTemplateChild("sheet1") as BookPage;

            if ((bp0 == null) || (bp1 == null))
            {
                return;
            }

            defaultDataTemplate = (DataTemplate)Resources["defaultDataTemplate"];
            Read <PageStatus>   GetStatus = delegate() { return(_status); };
            Action <PageStatus> SetStatus = delegate(PageStatus ps) { _status = ps; };

            bp0.GetStatus += GetStatus;
            bp0.SetStatus += SetStatus;
            bp1.GetStatus += GetStatus;
            bp1.SetStatus += SetStatus;

            RefreshSheetsContent();
        }
        private void RefreshSheetsContent()
        {
            BookPage bp0 = GetTemplateChild("sheet0") as BookPage;

            if (bp0 == null)
            {
                return;
            }

            BookPage bp1 = GetTemplateChild("sheet1") as BookPage;

            if (bp1 == null)
            {
                return;
            }

            ContentPresenter sheet0Page0Content = bp0.FindName("page0") as ContentPresenter;
            ContentPresenter sheet0Page1Content = bp0.FindName("page1") as ContentPresenter;
            ContentPresenter sheet0Page2Content = bp0.FindName("page2") as ContentPresenter;

            ContentPresenter sheet1Page0Content = bp1.FindName("page0") as ContentPresenter;
            ContentPresenter sheet1Page1Content = bp1.FindName("page1") as ContentPresenter;
            ContentPresenter sheet1Page2Content = bp1.FindName("page2") as ContentPresenter;

            Visibility bp0Visibility = Visibility.Visible;
            Visibility bp1Visibility = Visibility.Visible;

            bp1.IsTopRightCornerEnabled    = true;
            bp1.IsBottomRightCornerEnabled = true;

            Visibility sheet0Page0ContentVisibility = Visibility.Visible;
            Visibility sheet0Page1ContentVisibility = Visibility.Visible;
            Visibility sheet0Page2ContentVisibility = Visibility.Visible;
            Visibility sheet1Page0ContentVisibility = Visibility.Visible;
            Visibility sheet1Page1ContentVisibility = Visibility.Visible;
            Visibility sheet1Page2ContentVisibility = Visibility.Visible;

            DataTemplate dt = ItemTemplate;

            if (dt == null)
            {
                dt = defaultDataTemplate;
            }

            sheet0Page0Content.ContentTemplate = dt;
            sheet0Page1Content.ContentTemplate = dt;
            sheet0Page2Content.ContentTemplate = dt;
            sheet1Page0Content.ContentTemplate = dt;
            sheet1Page1Content.ContentTemplate = dt;
            sheet1Page2Content.ContentTemplate = dt;

            sheet0Page2ContentVisibility = _currentSheetIndex == 1 ? Visibility.Hidden : Visibility.Visible;
            int  count      = GetItemsCount();
            int  sheetCount = count / 2;
            bool isOdd      = (count % 2) == 1;

            if (_currentSheetIndex == sheetCount)
            {
                if (isOdd)
                {
                    bp1.IsTopRightCornerEnabled    = false;
                    bp1.IsBottomRightCornerEnabled = false;
                }
                else
                {
                    bp1Visibility = Visibility.Hidden;
                }
            }

            if (_currentSheetIndex == sheetCount - 1)
            {
                if (!isOdd)
                {
                    sheet1Page2ContentVisibility = Visibility.Hidden;
                }
            }

            if (_currentSheetIndex == 0)
            {
                sheet0Page0Content.Content = null;
                sheet0Page1Content.Content = null;
                sheet0Page2Content.Content = null;
                bp0.IsEnabled = false;
                bp0Visibility = Visibility.Hidden;
            }
            else
            {
                sheet0Page0Content.Content = GetPage(2 * (CurrentSheetIndex - 1) + 1);
                sheet0Page1Content.Content = GetPage(2 * (CurrentSheetIndex - 1));
                sheet0Page2Content.Content = GetPage(2 * (CurrentSheetIndex - 1) - 1);
                bp0.IsEnabled = true;
            }

            sheet1Page0Content.Content = GetPage(2 * CurrentSheetIndex);
            sheet1Page1Content.Content = GetPage(2 * CurrentSheetIndex + 1);
            sheet1Page2Content.Content = GetPage(2 * CurrentSheetIndex + 2);

            bp0.Visibility = bp0Visibility;
            bp1.Visibility = bp1Visibility;

            sheet0Page0Content.Visibility = sheet0Page0ContentVisibility;
            sheet0Page1Content.Visibility = sheet0Page1ContentVisibility;
            sheet0Page2Content.Visibility = sheet0Page2ContentVisibility;
            sheet1Page0Content.Visibility = sheet1Page0ContentVisibility;
            sheet1Page1Content.Visibility = sheet1Page1ContentVisibility;
            sheet1Page2Content.Visibility = sheet1Page2ContentVisibility;
        }