|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CBR.ViewModels;
namespace CBR.Views
{
/// <summary>
/// Interaction logic for BookView.xaml
/// </summary>
public partial class BookView : UserControl
{
#region -----------------private and constructor-----------------
public BookView()
{
InitializeComponent();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
this.PageViewer.Focus();
this.PageViewer.OnPageNeeded += new Components.Controls.PageControl.PageNeededEventHandler(PageViewer_OnPageNeeded);
this.PageViewer.OnZoomChanged += new Components.Controls.PageControl.ZoomChangedEventHandler(PageViewer_OnZoomChanged);
}
void PageViewer_OnZoomChanged(object sender, Components.Controls.PageControl.ZoomRoutedEventArgs e)
{
ComicViewModel bvm = DataContext as ComicViewModel;
bvm.Scale = e.Scale;
}
void PageViewer_OnPageNeeded(object sender, Components.Controls.PageControl.PageRoutedEventArgs e)
{
ComicViewModel bvm = DataContext as ComicViewModel;
if( bvm.IsInEditMode )
bvm.CurrentPage.Frames = this.PageViewer.FrameList;
bvm.BookChangePageCommand.Execute( e.PageOffset.ToString() );
}
#endregion
#region -----------------EVENTS-----------------
/// <summary>
/// update the magnifier
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PageViewer_PreviewMouseMove(object sender, MouseEventArgs e)
{
//manage the magnifier
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
if (Magnifier.Visibility == System.Windows.Visibility.Visible)
Magnifier.Update(Mouse.GetPosition(PageViewerGrid));
e.Handled = true;
}
}
private void PageViewer_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
//manage the magnifier
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
Magnifier.Update(Mouse.GetPosition(PageViewerGrid));
Magnifier.Visibility = Visibility.Visible;
this.PageViewer.CaptureMouse();
e.Handled = true;
}
}
private void PageViewer_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
//manage the magnifier
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
{
Magnifier.Visibility = Visibility.Hidden;
this.PageViewer.ReleaseMouseCapture();
e.Handled = true;
}
}
private void PageViewer_PreviewKeyDown(object sender, KeyEventArgs e)
{
//manage the magnifier
if ((Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) && Mouse.LeftButton == MouseButtonState.Pressed)
{
Magnifier.Update(Mouse.GetPosition(PageViewerGrid));
Magnifier.Visibility = Visibility.Visible;
this.PageViewer.CaptureMouse();
e.Handled = true;
}
}
private void PageViewer_PreviewKeyUp(object sender, KeyEventArgs e)
{
//manage the magnifier
if (!Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.RightCtrl))
{
Magnifier.Visibility = Visibility.Hidden;
this.PageViewer.ReleaseMouseCapture();
e.Handled = true;
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
WPF and MVVM fan, I practice C # in all its forms from the beginning of the NET Framework without mentioning C ++ / MFC and other software packages such as databases, ASP, WCF, Web & Windows services, Application, and now Core and UWP.
In my wasted hours, I am guilty of having fathered C.B.R. and its cousins C.B.R. for WinRT and UWP on the Windows store.
But apart from that, I am a great handyman ... the house, a rocket stove to heat the jacuzzi and the last one: a wood oven for pizza, bread, and everything that goes inside
https://guillaumewaser.wordpress.com/
https://fouretcompagnie.wordpress.com/