Exemple #1
0
        private void RefreshContent()
        {
            // show left and right content
            BookPage         sheet0 = GetTemplateChild("x_sheet_0") as BookPage;
            ContentPresenter p0     = sheet0.FindName("x_page_0") as ContentPresenter;
            ContentPresenter p1     = sheet0.FindName("x_page_1") as ContentPresenter;
            ContentPresenter p2     = sheet0.FindName("x_page_2") as ContentPresenter;

            p2.Content     = GetPage(_startPage + 0);
            p1.Content     = GetPage(_startPage + 1);
            p0.Content     = GetPage(_startPage + 2);
            sheet0.CanDrag = _startPage > -3;

            BookPage         sheet1 = GetTemplateChild("x_sheet_1") as BookPage;
            ContentPresenter ps0    = sheet1.FindName("x_page_0") as ContentPresenter;
            ContentPresenter ps1    = sheet1.FindName("x_page_1") as ContentPresenter;
            ContentPresenter ps2    = sheet1.FindName("x_page_2") as ContentPresenter;

            ps0.Content    = GetPage(_startPage + 3);
            ps1.Content    = GetPage(_startPage + 4);
            ps2.Content    = GetPage(_startPage + 5);
            sheet1.CanDrag = (_startPage + 3) < Items.Count;

            // make corner visible
            ClearBoxes(sheet0);
            ClearBoxes(sheet1);
        }
Exemple #2
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            _startPage = -3;
            Items.Insert(0, new Cover());
            if (Items.Count % 2 == 0)
            {
                // todo Empty
                Items.Add(new EmptyPage());
            }

            Items.Add(new EndCover());

            Assembly assem = Assembly.GetExecutingAssembly();
            Uri      ur    = new Uri(assem.CodeBase);
            FileInfo fi    = new FileInfo(ur.AbsolutePath);
            string   s     = fi.Directory.FullName;

            for (int i = 1; i < Items.Count - 1; i++)
            {
                UserControl el     = Items[i] as UserControl;
                ImageSource source = new BitmapImage(new Uri(s + "\\..\\..\\..\\book\\back.jpg"));
                ImageBrush  b      = new ImageBrush(source);
                el.BorderBrush     = b;
                el.BorderThickness = new Thickness(30);
                el.Background      = Brushes.SandyBrown;
            }

            BookPage s1 = GetTemplateChild("x_sheet_1") as BookPage;

            s1.StartPoint = new Point(s1.RenderSize.Width, 0);
            RefreshContent();
        }
Exemple #3
0
        private void AnimateToLeft(object sender, EventArgs e)
        {
            BookPage s0 = GetTemplateChild("x_sheet_1") as BookPage;
            Point    p  = FinalPoint;

            s0.StartDragging(p);
        }
Exemple #4
0
        private void ClearBoxes(BookPage sheet)
        {
            // clear all paths
            PathGeometry p = sheet.x_clip_page_2;

            p.Figures.Clear();
            sheet.x_clip_page_1.Figures.Clear();
            sheet.x_rectangleRotate.Angle = 0;
            sheet.x_rectangleTranslate.X  = 0;
            sheet.x_rectangleTranslate.Y  = 0;
        }
Exemple #5
0
        private void ContentControl_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (_isDragging == null)
            {
                return;
            }
            // set animation to finish
            BookPage b = _isDragging;

            _isDragging = null;
            Point p = e.GetPosition(b);

            // free old animation - todo change
            this.BeginAnimation(BookContainer.FinalPointProperty, null);
            FinalPoint = p;
            PointAnimation anim = new PointAnimation();

            anim.Duration    = new Duration(new TimeSpan(0, 0, 2));
            anim.From        = p;
            mAnimationActive = true;

            if (p.X > b.RenderSize.Width)
            {
                anim.To = new Point(2 * b.RenderSize.Width, 0);
                anim.CurrentTimeInvalidated += AnimateToRight;
                anim.Completed += Anim_Completed_Right;
            }
            else if (p.X < 0)
            {
                anim.To = new Point(-b.RenderSize.Width, 0);
                anim.CurrentTimeInvalidated += AnimateToLeft;
                anim.Completed += Anim_Completed_Left;
            }
            else
            {
                BookPage comp = GetTemplateChild("x_sheet_0") as BookPage;
                if (comp == _isDragging)
                {
                    anim.To = new Point(0, 0);
                    anim.CurrentTimeInvalidated += AnimateToLeft;
                    anim.Completed += Anim_Completed;
                }
                else
                {
                    anim.To = new Point(b.RenderSize.Width, 0);
                    anim.CurrentTimeInvalidated += AnimateToLeft;
                    anim.Completed += Anim_Completed;
                }
            }
            this.BeginAnimation(BookContainer.FinalPointProperty, anim);
        }
Exemple #6
0
 private void ContentControl_MouseMove(object sender, MouseEventArgs e)
 {
     if (mAnimationActive)
     {
         return;
     }
     if (_isDragging == null)
     {
         UIElement holder    = sender as UIElement;
         Point     p         = e.GetPosition(holder);
         bool      startDrag = false;
         BookPage  b         = GetTemplateChild("x_sheet_0") as BookPage;
         if (p.X < b.RenderSize.Width)
         {
             if (_startPage == -3)
             {
                 return;
             }
             startDrag = (p.X < _cornerSize) && (p.Y < _cornerSize);
         }
         else
         {
             if (_startPage == Items.Count - 3)
             {
                 return;
             }
             b         = GetTemplateChild("x_sheet_1") as BookPage;
             startDrag = ((holder.RenderSize.Width - p.X) < _cornerSize) && (p.Y < _cornerSize);
         }
         if (startDrag)
         {
             b.StartDragging(e.GetPosition(b));
         }
         else
         {
             RefreshContent();
         }
         return;
     }
     _isDragging.StartDragging(e.GetPosition(_isDragging));
 }
Exemple #7
0
        private void ContentControl_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (mAnimationActive)
            {
                return;
            }
            BookPage s = sender as BookPage;

            if (s == null)
            {
                return;
            }
            if (s.CanDrag == false)
            {
                return;
            }

            Point p = e.GetPosition(s);

            if (((p.X < _cornerSize) && (p.Y < _cornerSize)) ||
                (((s.RenderSize.Width - p.X) < _cornerSize) && (p.Y < _cornerSize)))
            {
                _isDragging = s;
            }
            else
            {
                return;
            }

            BookPage s0 = GetTemplateChild("x_sheet_0") as BookPage;
            BookPage s1 = GetTemplateChild("x_sheet_1") as BookPage;

            Canvas.SetZIndex(s0, 0);
            Canvas.SetZIndex(s1, 0);

            Canvas.SetZIndex(s, 1);
            s.StartDragging(p);
        }