1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057 |
- using PDF_Master.EventAggregators;
- using PDF_Master.Helper;
- using PDF_Master.Model.PageEdit;
- using PDF_Master.ViewModels.PageEdit;
- using Prism.Events;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- 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 System.Windows.Threading;
- using WpfToolkit.Controls;
- namespace PDF_Master.Views.PageEdit
- {
-
-
-
- public partial class PageEditContent : UserControl
- {
-
-
-
-
- private IEventAggregator eventor;
-
-
-
- private string unicode;
-
-
-
- private bool isFirstScrollChange = true;
-
-
-
- private DispatcherTimer timer = new DispatcherTimer();
-
-
-
- private bool startChoose = false;
-
-
-
- private Point starPosition = new Point();
-
-
-
- private ScrollEventType scrolltype = ScrollEventType.EndScroll;
-
- private double item_x;
- private double item_y;
-
- private int InsertIndex = -1;
-
- private PageEditItem tempItem;
-
-
-
- private bool isDraging = false;
-
- public bool isDragingEnter { get; set; } = false;
-
-
-
- private bool needScroll = false;
-
- private int speed = 0;
- private PageEditContentViewModel viewModel;
- public PageEditContent()
- {
- InitializeComponent();
- }
- private void PageEditItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
- {
-
- if (GridBOTAHeader.Visibility == Visibility.Visible&&e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
- {
- ItemSuitAcutalWidth(this.ActualWidth);
- }
-
- eventor.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs(unicode,NotifyType.PageCountChanged));
- }
- public PageEditContent(IEventAggregator eventAggregator) : this()
- {
- eventor = eventAggregator;
- unicode = App.mainWindowViewModel.SelectedItem.Unicode;
- timer = new DispatcherTimer();
- timer.Interval = TimeSpan.FromSeconds(0.3);
- timer.Tick += Timer_Tick;
- viewModel = this.DataContext as PageEditContentViewModel;
- viewModel.PageEditItems.CollectionChanged += PageEditItems_CollectionChanged;
-
- eventor.GetEvent<PageEditNotifyEvent>().Subscribe(OneNotifyEvent, e => e.Unicode == unicode);
- eventAggregator.GetEvent<CleanSelectAllEvent>().Subscribe(CleanSelectAll, e => e.Unicode == unicode);
- }
- private void CleanSelectAll(CleanSelectAllArgs obj)
- {
- ListPageEdit.SelectedItems.Clear();
- ListPageEdit.SelectedIndex = viewModel.PDFViewer.CurrentIndex;
- }
- private void Timer_Tick(object sender, EventArgs e)
- {
- PulishEvent();
- timer?.Stop();
- }
- private void OneNotifyEvent(PageEditNotifyEventArgs e)
- {
- switch (e.Type)
- {
- case NotifyType.RefreshPage:
- PulishEvent();
- break;
- case NotifyType.SelectItems:
- if (e.PageRange.Count == 1)
- {
- ListPageEdit.SelectedIndex = e.PageRange[0] - 1;
- ListPageEdit.ScrollIntoView(ListPageEdit.SelectedItem);
- }
- else
- {
- ListPageEdit.SelectedItems.Clear();
- for (int i = 0; i < e.PageRange.Count; i++)
- {
- ListPageEdit.SelectedItems.Add(ListPageEdit.Items[e.PageRange[i] - 1]);
- }
- }
- break;
- }
- }
- #region UI事件
-
-
-
-
-
- private void PageEdit_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- if ((bool)e.NewValue)
- {
-
- PulishEvent();
-
- isFirstScrollChange = true;
- if (GridBOTAHeader.Visibility == Visibility.Visible)
- {
- ItemSuitAcutalWidth(this.ActualWidth);
- }
- }
- }
-
-
-
-
-
- private void ListPageEdit_ScrollChanged(object sender, ScrollChangedEventArgs e)
- {
- if (isFirstScrollChange)
- {
- PulishEvent();
- isFirstScrollChange = false;
- return;
- }
- else
- {
- if (e.VerticalChange != 0)
- timer?.Start();
- }
- }
-
-
-
-
-
- private void ListPageEdit_Scroll(object sender, System.Windows.Controls.Primitives.ScrollEventArgs e)
- {
- scrolltype = e.ScrollEventType;
- if (scrolltype != System.Windows.Controls.Primitives.ScrollEventType.EndScroll)
- {
- timer?.Stop();
- return;
- }
- PulishEvent();
- }
- #endregion
- #region 方法
-
-
-
- private void PulishEvent()
- {
-
- if (ListPageEdit != null & ListPageEdit.Items.Count > 0)
- {
- var itemSize = new Size((ListPageEdit.Items[0] as PageEditItem).ItemSize.Width + 32, (ListPageEdit.Items[0] as PageEditItem).ItemSize.Height + 30);
- var range = GetRoughFromView(ListPageEdit, itemSize, new Thickness(5, 10, 5, 10));
- if ((bool)TbnTwoLine.IsChecked)
- {
-
- range = new Tuple<int, int, int>(range.Item1, range.Item2 * 2, range.Item3);
- }
- eventor.GetEvent<PageEditRefreshEvent>().Publish(new PageEditRefreshEventArgs() { Unicode = unicode, PageRange = range });
- }
- }
-
-
-
-
-
-
-
-
- private Tuple<int, int, int> GetRoughFromView(ListBox view, Size itemSize, Thickness itemMargin)
- {
-
- var scrollViewer = CommonHelper.FindVisualChild<ScrollViewer>(view);
- if (scrollViewer == null || scrollViewer.ActualHeight == 0 || scrollViewer.ActualWidth == 0)
- return new Tuple<int, int, int>(0, 0, 0);
- try
- {
- var currentHeight = scrollViewer.ActualHeight - view.Padding.Top;
- var currentWidth = scrollViewer.ActualWidth;
-
- var columnCount = (int)(currentWidth / (itemSize.Width + itemMargin.Left));
- var rowCount = (int)Math.Ceiling(currentHeight / (itemSize.Height + itemMargin.Bottom));
- var preItemCount = (int)((scrollViewer.VerticalOffset / scrollViewer.ExtentHeight) * ((view.Items.Count + columnCount - 1) / columnCount));
- preItemCount = preItemCount * columnCount;
- var preEnd = (int)(((scrollViewer.VerticalOffset + scrollViewer.ActualHeight) / scrollViewer.ExtentHeight) * ((view.Items.Count + columnCount - 1) / columnCount));
- preEnd = preEnd * columnCount + columnCount - 1;
- var middle = (int)Math.Ceiling(preItemCount + preEnd / 2d);
- return new Tuple<int, int, int>(
- Math.Max(preItemCount, 0),
- Math.Min(view.Items.Count, preEnd),
- middle);
- }
- catch { }
- return new Tuple<int, int, int>(0, 0, 0);
- }
-
-
-
-
-
-
- private ScrollViewer GetScrollHost(ListBox listBox)
- {
- if (VisualTreeHelper.GetChildrenCount(listBox) > 0)
- {
- int s = VisualTreeHelper.GetChildrenCount(listBox);
- Border border = VisualTreeHelper.GetChild(listBox, 0) as Border;
- if (border != null)
- {
- return VisualTreeHelper.GetChild(border, 0) as ScrollViewer;
- }
- }
- return null;
- }
- #endregion
-
-
-
-
-
- private void TextBox_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- if ((bool)e.NewValue)
- {
- (sender as Control).Focus();
- }
- }
- private void ListPageEdit_PreviewMouseMove(object sender, MouseEventArgs e)
- {
- try
- {
- if (e.LeftButton == MouseButtonState.Pressed&&!isDragingEnter)
- {
-
-
- if (startChoose)
- {
- var position = e.GetPosition(ListPageEdit);
- if (position.X < 5 || position.X > ListPageEdit.ActualWidth - 5 || position.Y < 5 || position.Y > ListPageEdit.ActualHeight - 5)
- {
- startChoose = false;
- RectChoose.Visibility = Visibility.Collapsed;
-
- Mouse.Capture(null);
- return;
- }
-
- DoSelectItems();
- return;
- }
-
- var pos = e.GetPosition(ListPageEdit);
- if (pos.Y < 0 || pos.Y > ListPageEdit.ActualHeight)
- {
- LineInset.Visibility = Visibility.Collapsed;
- ImgPicture.Visibility = Visibility.Collapsed;
- return;
- }
- HitTestResult result = VisualTreeHelper.HitTest(ListPageEdit, pos);
- if (result == null)
- {
- return;
- }
- var listBoxItem = CommonHelper.FindVisualParent<ListBoxItem>(result.VisualHit);
- if (listBoxItem == null)
- {
- return;
- }
- isDragingEnter = false;
- tempItem = listBoxItem.DataContext as PageEditItem;
- var item_pos = e.GetPosition(listBoxItem);
- if (item_pos != null)
- {
- item_x = item_pos.X;
- item_y = item_pos.Y;
- }
- var scroll = GetScrollHost(ListPageEdit);
- string filename = Guid.NewGuid().ToString() + ".pdf";
- string tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), filename);
- System.IO.File.Create(tempPath);
- string[] files = new string[1];
- files[0] = tempPath;
-
-
- DataObject dataObj = new DataObject(listBoxItem);
- DragDrop.DoDragDrop(ListPageEdit, dataObj, DragDropEffects.Copy);
- Mouse.Capture(ListPageEdit);
- return;
- }
- RectChoose.Visibility = Visibility.Collapsed;
- startChoose = false;
- Mouse.Capture(null);
- }
- catch
- {
- LineInset.Visibility = Visibility.Collapsed;
- ImgPicture.Visibility = Visibility.Collapsed;
- }
- }
-
-
-
-
-
- private void ListPageEdit_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- var pos = e.GetPosition(ListPageEdit);
- HitTestResult result = VisualTreeHelper.HitTest(ListPageEdit, pos);
- if (result == null)
- {
- return;
- }
-
- var listBoxItem = CommonHelper.FindVisualParent<ListBoxItem>(result.VisualHit);
- var scroller = CommonHelper.FindVisualParent<ScrollBar>(result.VisualHit);
- if (listBoxItem == null)
- {
- if (scroller != null)
- {
- startChoose = false;
- return;
- }
-
- startChoose = true;
- if (ListPageEdit.SelectedItems.Count > 0)
- {
- ListPageEdit.SelectedItems.Clear();
- }
- starPosition = e.GetPosition(ListPageEdit);
- starPosition = new Point(starPosition.X, starPosition.Y + GetWrapPanel(ListPageEdit).VerticalOffset);
- Mouse.Capture(ListPageEdit);
- return;
- }
-
- startChoose = false;
-
-
-
-
- if (listBoxItem.IsSelected == true && !Keyboard.IsKeyDown(Key.LeftCtrl))
- {
- e.Handled = true;
- }
-
-
-
-
- }
- private void ListPageEdit_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- var pos = e.GetPosition(ListPageEdit);
- HitTestResult result = VisualTreeHelper.HitTest(ListPageEdit, pos);
- if (result == null)
- {
- return;
- }
- var listBoxItem = CommonHelper.FindVisualParent<ListBoxItem>(result.VisualHit);
- if (listBoxItem == null)
- {
- return;
- }
-
-
- if (!startChoose && !Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.LeftShift))
- {
- ListPageEdit.SelectedItems.Clear();
- ListPageEdit.SelectedItem = listBoxItem;
- listBoxItem.IsSelected = true;
- return;
- }
- Mouse.Capture(null);
-
- startChoose = false;
- RectChoose.Visibility = Visibility.Collapsed;
- }
-
-
-
-
-
- public VirtualizingWrapPanel GetWrapPanel(ListBox listBox)
- {
- Border border = VisualTreeHelper.GetChild(listBox, 0) as Border;
- var panel = CommonHelper.FindVisualChild<VirtualizingWrapPanel>(border);
- return panel;
- }
-
-
-
- private void DoSelectItems()
- {
- var s = GetScrollHost(ListPageEdit);
- Point start = new Point();
-
- start = new Point(starPosition.X, starPosition.Y - s.VerticalOffset);
- var rec = new Rect(start, Mouse.GetPosition(ListPageEdit));
- RectChoose.Margin = new Thickness(rec.Left, rec.Top, 0, 0);
- RectChoose.Width = rec.Width;
- RectChoose.Height = rec.Height;
- RectChoose.Visibility = Visibility.Visible;
-
- for (int i = 0; i < ListPageEdit.Items.Count; i++)
- {
- var _item = ListPageEdit.ItemContainerGenerator.ContainerFromIndex(i) as ListBoxItem;
-
- var parent = CommonHelper.FindVisualParent<VirtualizingWrapPanel>(_item);
- if (parent == null)
- continue;
- var v = VisualTreeHelper.GetOffset(_item);
- if (rec.IntersectsWith(new Rect(v.X, v.Y, _item.ActualWidth, _item.ActualHeight)))
- {
- ListPageEdit.SelectedItems.Add(ListPageEdit.Items[i]);
- }
- else
- {
- ListPageEdit.SelectedItems.Remove(ListPageEdit.Items[i]);
- }
- }
- return;
- }
-
-
-
- private void ExitDraging()
- {
- LineInset.Visibility = Visibility.Collapsed;
- ImgPicture.Visibility = Visibility.Collapsed;
- isDraging = false;
- }
-
-
-
-
-
- private async void ListPageEdit_Drop(object sender, DragEventArgs e)
- {
- needScroll = false;
- if (!isDraging)
- {
-
- LineInset.Visibility = Visibility.Collapsed;
- ImgPicture.Visibility = Visibility.Collapsed;
- return;
- }
-
- string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
- if (file != null)
- {
- return;
- }
- #region 功能付费锁
-
-
-
-
-
-
-
- #endregion
- #region 从外部拖拽插入文件
- if (isDragingEnter)
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return;
- }
- #endregion
- var pos = e.GetPosition(ListPageEdit);
- var result = VisualTreeHelper.HitTest(ListPageEdit, pos);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- int targetindex = 0;
- if (InsertIndex != -1)
- {
-
- targetindex = InsertIndex;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- List<ListBoxItem> list = new List<ListBoxItem>();
- List<int> sourceindex = new List<int>();
-
- List<int> pages = new List<int>();
-
- for (int i = 0; i < ListPageEdit.SelectedItems.Count; i++)
- {
- var pageindex = ListPageEdit.Items.IndexOf(ListPageEdit.SelectedItems[i] as PageEditItem);
- pages.Add(pageindex);
- }
- if (pages.Count <= 0)
- {
- ExitDraging();
- return;
- }
- viewModel.DragToSort(targetindex,pages);
- ExitDraging();
- isDraging = false;
- }
- private void MidLane_Drop(object sender, DragEventArgs e)
- {
- ListPageEdit_Drop(sender, e);
- }
- private void ImgPicture_Drop(object sender, DragEventArgs e)
- {
- ListPageEdit_Drop(sender, e);
- }
-
-
-
-
-
- private void Grid_DragOver(object sender, DragEventArgs e)
- {
- try
- {
-
- if (e.KeyStates == (DragDropKeyStates.ControlKey | DragDropKeyStates.LeftMouseButton) || e.KeyStates == (DragDropKeyStates.ShiftKey | DragDropKeyStates.LeftMouseButton | DragDropKeyStates.ControlKey))
- return;
-
- string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
- if(file!=null)
- {
- return;
- }
-
-
- var pos = e.GetPosition(ListPageEdit);
- var result = VisualTreeHelper.HitTest(ListPageEdit, pos);
- if (result == null)
- {
- return;
-
-
- }
-
- var listBoxItem = CommonHelper.FindVisualParent<ListBoxItem>(result.VisualHit);
- if (listBoxItem == null)
- {
-
-
- }
- #region 计算虚影位置
-
- double xPos = 0;
- double yPos = 0;
-
- if (!isDragingEnter)
- {
- if(tempItem!=null)
- {
- ImgPicture.Width = tempItem.ItemSize.Width;
- ImgPicture.Height = tempItem.ItemSize.Height;
- ImgPicture.Source = tempItem.Image;
- xPos = e.GetPosition(ListPageEdit).X - item_x;
- yPos = e.GetPosition(ListPageEdit).Y - item_y;
- }
- }
- else
- {
- DragDropHelper.DragOver(this, e);
-
-
-
-
-
-
-
- }
- ImgPicture.Margin = new Thickness(xPos, yPos, 0, 0);
- #endregion
- #region 计算插入标记位置
- var scroll = GetScrollHost(ListPageEdit);
- if (listBoxItem != null)
- {
-
- var p = VisualTreeHelper.GetOffset(listBoxItem);
- LineInset.Visibility = Visibility.Visible;
- if(!isDragingEnter)
- {
- ImgPicture.Visibility = Visibility.Visible;
- }
- else
- {
- ImgPicture.Visibility = Visibility.Collapsed;
- }
- var panel = GetWrapPanel(ListPageEdit);
-
-
- var item = listBoxItem.DesiredSize.Width;
- int count = (int)(panel.ViewportWidth / item);
- var gap = (panel.ViewportWidth - count * item) / (count + 1) * 1.0;
- LineInset.X2 = LineInset.X1 = p.X + gap / 2 + listBoxItem.DesiredSize.Width;
- if (pos.X < p.X + gap / 2 + listBoxItem.ActualWidth / 2)
- {
- LineInset.X2 = LineInset.X1 = p.X - gap / 2;
- InsertIndex = ListPageEdit.Items.IndexOf(listBoxItem.DataContext as PageEditItem);
- }
- else
- {
- InsertIndex = ListPageEdit.Items.IndexOf(listBoxItem.DataContext as PageEditItem) + 1;
- }
- Console.WriteLine("InsertIndex:{0}\r\n",InsertIndex);
-
- LineInset.Y1 = p.Y;
- if (LineInset.Y1 < 0)
- {
- LineInset.Y1 = 0;
- }
-
- LineInset.Y2 = p.Y + listBoxItem.ActualHeight;
- if (LineInset.Y2 < 0)
- {
- LineInset.Y2 = 0;
- }
- }
- #endregion
-
- if (pos.Y <= 30 || pos.Y >= ListPageEdit.ActualHeight - 10)
- {
- LineInset.Visibility = Visibility.Collapsed;
- ImgPicture.Visibility = Visibility.Collapsed;
- needScroll = false;
- }
- if (pos.X <= 40 || pos.X >= scroll.ViewportWidth - 50)
- {
- LineInset.Visibility = Visibility.Collapsed;
- ImgPicture.Visibility = Visibility.Collapsed;
- needScroll = false;
- }
- #region 靠近上下边界时,自动滚动,离边界越近,滚动速度越快
- speed = 0;
- if (pos.Y >= ListPageEdit.ActualHeight - 30)
- {
- speed = 30 - (int)(ListPageEdit.ActualHeight - pos.Y);
- needScroll = true;
- }
- else if (pos.Y <= 30)
- {
- speed = (int)(pos.Y - 30);
- needScroll = true;
- }
- else
- needScroll = false;
- var v = scroll.VerticalOffset;
- scroll.ScrollToVerticalOffset(v + speed);
- #endregion
- }
- catch
- {
- }
- }
- private void ListBoxItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- if(GridBOTAHeader.Visibility == Visibility.Visible&&viewModel.PDFViewer!=null)
- {
- if(Keyboard.Modifiers == ModifierKeys.Shift||Keyboard.Modifiers== ModifierKeys.Control)
- {
- return;
- }
- var item = (sender as ListBoxItem).DataContext as PageEditItem;
- if(item != null)
- {
- viewModel.PDFViewer.GoToPage(item.PageNumber-1);
- }
- }
- }
- private void ListBoxItem_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
- if (e.ChangedButton == MouseButton.Left)
- {
-
- var item = sender as ListBoxItem;
- if (item != null)
- {
- var index = ListPageEdit.ItemContainerGenerator.IndexFromContainer(item);
-
- viewModel.BackToPDFViewer(index);
- }
- }
- }
- private void PageEdit_SizeChanged(object sender, SizeChangedEventArgs e)
- {
-
- if (GridBOTAHeader.Visibility == Visibility.Visible)
- {
- ItemSuitAcutalWidth(e.NewSize.Width);
- }
- if(e.NewSize.Width>0)
- {
-
- PulishEvent();
- }
- }
- private void ItemSuitAcutalWidth(double width)
- {
-
- if ((bool)TbnTwoLine.IsChecked)
- {
- var itemwidth = (width - 140) / 2;
- if(itemwidth<0)
- {
- itemwidth = width / 4;
- }
- var itemHeight = 294 * itemwidth / 208.0;
- viewModel.ChangeItemSize(new Size(itemwidth, itemHeight));
- }
- else
- {
- var itemwidth = 0.6 * width;
- var itemheight = 294 * itemwidth / 208.0;
- viewModel.ChangeItemSize(new Size(itemwidth, itemheight));
- }
- }
- private void TbnTwoLine_Click(object sender, RoutedEventArgs e)
- {
- ItemSuitAcutalWidth(this.ActualWidth);
- PulishEvent();
- }
-
-
-
-
-
- private void Grid_PreviewDragEnter(object sender, DragEventArgs e)
- {
- var file = (System.Array)e.Data.GetData(DataFormats.FileDrop);
- if (file == null)
- {
- return;
- }
- isDragingEnter = false;
- foreach (string f in file)
- {
- System.IO.FileInfo info = new System.IO.FileInfo(f);
-
- if (System.IO.Path.GetExtension(f).ToLower() == ".pdf" && info.Length > 0)
- {
- isDragingEnter = true;
- }
- }
- DragDropHelper.DragEnter(this, e);
- }
- private void Grid_DragLeave(object sender, DragEventArgs e)
- {
- DragDropHelper.DragLeave();
- }
- private void Grid_Drop(object sender, DragEventArgs e)
- {
- DragDropHelper.Drop(this,e);
- }
- private void ListBoxItem_DragLeave(object sender, DragEventArgs e)
- {
-
-
- isDraging = true;
- }
- private void Border_Drop(object sender, DragEventArgs e)
- {
- }
- private async void TextBoxEx_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- var text = sender as TextBox;
- if(text!=null)
- {
- await Task.Delay(50);
- text.Focus();
- }
- }
- private void TextBoxEx_TextChanged(object sender, TextChangedEventArgs e)
- {
- var text = sender as TextBox;
- if(text.Visibility==Visibility.Visible&&string.IsNullOrEmpty(text.Text))
- {
- text.Focus();
- }
- }
- private void TextBoxEx_LostFocus(object sender, RoutedEventArgs e)
- {
-
- var element = FocusManager.GetFocusedElement(this);
- var visual = VisualTreeHelper.HitTest(this, Mouse.GetPosition(this));
-
- if (visual != null)
- {
- var listbox = CommonHelper.FindVisualParent<ListBox>(visual.VisualHit);
- if (listbox != null)
- {
-
- return;
- }
- var image = CommonHelper.FindVisualParent<Image>(visual.VisualHit);
- if (image != null)
- {
-
- return;
- }
- var button =CommonHelper.FindVisualParent<Button>(visual.VisualHit);
- if(button!=null)
- {
-
- return;
- }
- var combox = CommonHelper.FindVisualParent<ComboBox>(visual.VisualHit);
- if(combox!=null)
- {
-
- return;
- }
- viewModel.lostfocus(e);
- }
- }
- private void Grid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- var visual = VisualTreeHelper.HitTest(this, Mouse.GetPosition(this));
- if (visual!=null&&(visual.VisualHit as Grid)!=null)
- {
-
- ListPageEdit.Focus();
- }
- }
- private void MenuItem_Click(object sender, RoutedEventArgs e)
- {
-
- List<int> lists = new List<int>();
- foreach(PageEditItem item in ListPageEdit.SelectedItems)
- {
- lists.Add(item.PageNumber);
- }
- viewModel.print(lists);
- }
- private void PageEdit_Unloaded(object sender, RoutedEventArgs e)
- {
-
- timer?.Stop();
- if (timer != null)
- {
- timer.Tick -= Timer_Tick;
- timer = null;
- }
- }
- private void PageEdit_Loaded(object sender, RoutedEventArgs e)
- {
- if (timer == null)
- {
- timer = new DispatcherTimer();
- timer.Tick += Timer_Tick;
- }
- }
- }
- }
|