PDFPathEditControl.xaml.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. using ComPDFKit.Import;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKit.PDFPage;
  4. using ComPDFKit.PDFPage.Edit;
  5. using ComPDFKit.Tool;
  6. using ComPDFKit.Tool.UndoManger;
  7. using ComPDFKit.Viewer.Helper;
  8. using ComPDFKitViewer;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Controls.Primitives;
  14. using System.Windows.Input;
  15. using ComPDFKit.Tool.DrawTool;
  16. using ComPDFKitViewer.Helper;
  17. using System.Linq;
  18. using System.ComponentModel;
  19. using System.Runtime.CompilerServices;
  20. using ComPDFKit.Tool.SettingParam;
  21. using System.Windows.Media;
  22. namespace ComPDFKit.Controls.Edit
  23. {
  24. public partial class PDFPathEditControl : UserControl, INotifyPropertyChanged
  25. {
  26. #region property
  27. public CPDFViewerTool ToolView { get; set; }
  28. public List<PathEditParam> EditEvents { get; set; } = new List<PathEditParam>();
  29. private Visibility _onlySingleVisible = Visibility.Collapsed;
  30. public Visibility OnlySingleVisible
  31. {
  32. get => _onlySingleVisible;
  33. set => UpdateProper(ref _onlySingleVisible, value);
  34. }
  35. #endregion
  36. public PDFPathEditControl()
  37. {
  38. DataContext = this;
  39. InitializeComponent();
  40. Loaded += PDPathEditControl_Loaded;
  41. Unloaded += PDFPathEditControl_Unloaded;
  42. }
  43. #region Load unload custom control
  44. private void PDPathEditControl_Loaded(object sender, RoutedEventArgs e)
  45. {
  46. RotateUI.RotationChanged -= RotateUI_RotationChanged;
  47. FlipUI.FlipChanged -= FlipUI_FlipChanged;
  48. RotateUI.RotationChanged += RotateUI_RotationChanged;
  49. FlipUI.FlipChanged += FlipUI_FlipChanged;
  50. ToolView.SelectedDataChanged -= ToolView_SelectedDataChanged;
  51. ToolView.SelectedDataChanged += ToolView_SelectedDataChanged;
  52. StrokeColorUI.ColorChanged -= StrokeColorUI_ColorChanged;
  53. StrokeColorUI.ColorChanged += StrokeColorUI_ColorChanged;
  54. FillColorUI.ColorChanged -= FillColorUI_ColorChanged;
  55. FillColorUI.ColorChanged += FillColorUI_ColorChanged;
  56. }
  57. private void StrokeColorUI_ColorChanged(object sender, EventArgs e)
  58. {
  59. SolidColorBrush newBrush = StrokeColorUI.Brush as SolidColorBrush;
  60. GetPathArea(out List<CPDFEditPathArea> pathAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
  61. if (pathAreas.Count == 0 || pdfPage == null || editPage == null)
  62. return;
  63. if (ToolView.CurrentEditAreaObject() != null)
  64. {
  65. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathAreas[0].GetFrame());
  66. bool result = pathAreas[0].SetStrokeColor(new byte[] { newBrush.Color.R, newBrush.Color.G, newBrush.Color.B});
  67. if (result)
  68. {
  69. PDFEditHistory editHistory = new PDFEditHistory();
  70. editHistory.EditPage = editPage;
  71. editHistory.PageIndex = pdfPage.PageIndex;
  72. ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
  73. ToolView.UpdateRender(oldRect, pathAreas[0]);
  74. }
  75. }
  76. else
  77. {
  78. GroupHistory groupHistory = new GroupHistory();
  79. foreach (CPDFEditPathArea pathArea in pathAreas)
  80. {
  81. if (pathArea.SetStrokeColor(new byte[] { newBrush.Color.R, newBrush.Color.G, newBrush.Color.B }))
  82. {
  83. PDFEditHistory editHistory = new PDFEditHistory();
  84. editHistory.EditPage = editPage;
  85. editHistory.PageIndex = pdfPage.PageIndex;
  86. groupHistory.Histories.Add(editHistory);
  87. }
  88. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
  89. ToolView.GetCPDFViewer()?.UpdateRenderFrame();
  90. }
  91. }
  92. editPage.EndEdit();
  93. if (EditEvents.Count > 0 && newBrush != null)
  94. {
  95. byte[] Color = new byte[3];
  96. Color[0] = newBrush.Color.R;
  97. Color[1] = newBrush.Color.G;
  98. Color[2] = newBrush.Color.B;
  99. EditEvents.FirstOrDefault().StrokeColor = Color;
  100. DefaultSettingParam defaultSettingParam = ToolView.GetDefaultSettingParam();
  101. defaultSettingParam.SetPDFEditParamm(EditEvents.FirstOrDefault());
  102. }
  103. }
  104. private void FillColorUI_ColorChanged(object sender, EventArgs e)
  105. {
  106. SolidColorBrush newBrush = FillColorUI.Brush as SolidColorBrush;
  107. GetPathArea(out List<CPDFEditPathArea> pathAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
  108. if (pathAreas.Count == 0 || pdfPage == null || editPage == null)
  109. return;
  110. if (ToolView.CurrentEditAreaObject() != null)
  111. {
  112. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathAreas[0].GetFrame());
  113. bool result = pathAreas[0].SetFillColor(new byte[] { newBrush.Color.R, newBrush.Color.G, newBrush.Color.B });
  114. if (result)
  115. {
  116. PDFEditHistory editHistory = new PDFEditHistory();
  117. editHistory.EditPage = editPage;
  118. editHistory.PageIndex = pdfPage.PageIndex;
  119. ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
  120. ToolView.UpdateRender(oldRect, pathAreas[0]);
  121. }
  122. }
  123. else
  124. {
  125. GroupHistory groupHistory = new GroupHistory();
  126. foreach (CPDFEditPathArea pathArea in pathAreas)
  127. {
  128. if (pathArea.SetFillColor(new byte[] { newBrush.Color.R, newBrush.Color.G, newBrush.Color.B }))
  129. {
  130. PDFEditHistory editHistory = new PDFEditHistory();
  131. editHistory.EditPage = editPage;
  132. editHistory.PageIndex = pdfPage.PageIndex;
  133. groupHistory.Histories.Add(editHistory);
  134. }
  135. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
  136. ToolView.GetCPDFViewer()?.UpdateRenderFrame();
  137. }
  138. }
  139. editPage.EndEdit();
  140. if (EditEvents.Count > 0 && newBrush != null)
  141. {
  142. byte[] Color = new byte[3];
  143. Color[0] = newBrush.Color.R;
  144. Color[1] = newBrush.Color.G;
  145. Color[2] = newBrush.Color.B;
  146. EditEvents.FirstOrDefault().FillColor = Color;
  147. DefaultSettingParam defaultSettingParam = ToolView.GetDefaultSettingParam();
  148. defaultSettingParam.SetPDFEditParamm(EditEvents.FirstOrDefault());
  149. }
  150. }
  151. private void PDFPathEditControl_Unloaded(object sender, RoutedEventArgs e)
  152. {
  153. RotateUI.RotationChanged -= RotateUI_RotationChanged;
  154. FlipUI.FlipChanged -= FlipUI_FlipChanged;
  155. }
  156. #endregion
  157. #region Property changed
  158. private void PathCut()
  159. {
  160. GetPathArea(out List<CPDFEditPathArea> pathAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
  161. if (pathAreas.Count == 0 || pdfPage == null || editPage == null)
  162. return;
  163. SelectedRect selectedRect = ToolView.GetSelectedRectForEditAreaObject(pathAreas[0]);
  164. if (selectedRect == null)
  165. return;
  166. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathAreas[0].GetFrame());
  167. double currentZoom = ToolView.GetCPDFViewer().CurrentRenderFrame.ZoomFactor;
  168. Rect rect = selectedRect.GetRect();
  169. Rect maxRect = selectedRect.GetMaxRect();
  170. Rect pdfRect = new Rect((rect.X - maxRect.X) / currentZoom, (rect.Y - maxRect.Y) / currentZoom, rect.Width / currentZoom, rect.Height / currentZoom);
  171. pdfRect = DpiHelper.StandardRectToPDFRect(pdfRect);
  172. CRect newCRect = new CRect((float)pdfRect.Left, (float)pdfRect.Bottom, (float)pdfRect.Right, (float)pdfRect.Top);
  173. if (pathAreas[0].CutWithRect(newCRect))
  174. {
  175. PDFEditHistory editHistory = new PDFEditHistory();
  176. editHistory.EditPage = editPage;
  177. editHistory.PageIndex = pdfPage.PageIndex;
  178. ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
  179. ToolView.UpdateRender(oldRect, pathAreas[0]);
  180. }
  181. editPage.EndEdit();
  182. }
  183. private void ToolView_SelectedDataChanged(object sender, SelectedAnnotData e)
  184. {
  185. if (ToolView.GetIsCropMode())
  186. {
  187. PathCut();
  188. }
  189. }
  190. #endregion
  191. #region Init PDFViewer
  192. public void InitWithPDFViewer(CPDFViewerTool newPDFView)
  193. {
  194. ToolView = newPDFView;
  195. }
  196. #endregion
  197. #region public method
  198. //public void SetRotationText(float rotation)
  199. //{
  200. // RotationTxb.Text = rotation.ToString(CultureInfo.CurrentCulture);
  201. //}
  202. #endregion
  203. #region Path Edit
  204. private void SetPathTransparency(double transparency)
  205. {
  206. PathOpacitySlider.Value = transparency / 255D;
  207. OpacityTextBox.Text = string.Format("{0}%", (int)(Math.Round(PathOpacitySlider.Value * 100)));
  208. }
  209. public void SetPDFPathEditData(List<PathEditParam> newEvents)
  210. {
  211. EditEvents = newEvents.Where(newEvent => newEvent.EditIndex >= 0 && newEvent.EditType == CPDFEditType.EditPath).ToList();
  212. if (EditEvents.Count == 0)
  213. return;
  214. PathEditParam defaultEvent = EditEvents.FirstOrDefault();
  215. SetPathTransparency(defaultEvent.Transparency);
  216. RotationTxb.Text = defaultEvent.Rotate.ToString();
  217. StrokeColorUI.SetCheckedForColor(Color.FromRgb(
  218. defaultEvent.StrokeColor[0],
  219. defaultEvent.StrokeColor[1],
  220. defaultEvent.StrokeColor[2]));
  221. FillColorUI.SetCheckedForColor(Color.FromRgb(
  222. defaultEvent.FillColor[0],
  223. defaultEvent.FillColor[1],
  224. defaultEvent.FillColor[2]));
  225. if (EditEvents.Count == 1)
  226. {
  227. OnlySingleVisible = Visibility.Visible;
  228. }
  229. else
  230. {
  231. OnlySingleVisible = Visibility.Collapsed;
  232. }
  233. }
  234. #endregion
  235. #region Property changed
  236. private void FlipUI_FlipChanged(object sender, bool e)
  237. {
  238. GetPathArea(out List<CPDFEditPathArea> pathAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
  239. if (pathAreas.Count == 0 || pdfPage == null || editPage == null)
  240. return;
  241. if (ToolView.CurrentEditAreaObject() != null)
  242. {
  243. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathAreas[0].GetFrame());
  244. bool result;
  245. if (e)
  246. {
  247. result = pathAreas[0].VerticalMirror();
  248. }
  249. else
  250. {
  251. result = pathAreas[0].HorizontalMirror();
  252. }
  253. if (result)
  254. {
  255. PDFEditHistory editHistory = new PDFEditHistory();
  256. editHistory.EditPage = editPage;
  257. editHistory.PageIndex = pdfPage.PageIndex;
  258. ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
  259. ToolView.UpdateRender(oldRect, pathAreas[0]);
  260. }
  261. }
  262. else
  263. {
  264. GroupHistory groupHistory = new GroupHistory();
  265. foreach (CPDFEditPathArea pathArea in pathAreas)
  266. {
  267. bool result;
  268. if (e)
  269. {
  270. result = pathArea.VerticalMirror();
  271. }
  272. else
  273. {
  274. result = pathArea.HorizontalMirror();
  275. }
  276. if (result)
  277. {
  278. PDFEditHistory editHistory = new PDFEditHistory();
  279. editHistory.EditPage = editPage;
  280. editHistory.PageIndex = pdfPage.PageIndex;
  281. groupHistory.Histories.Add(editHistory);
  282. }
  283. }
  284. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
  285. ToolView.GetCPDFViewer()?.UpdateRenderFrame();
  286. }
  287. editPage.EndEdit();
  288. }
  289. private void RotateUI_RotationChanged(object sender, double e)
  290. {
  291. GetPathArea(out List<CPDFEditPathArea> pathAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
  292. if (pathAreas.Count == 0 || pdfPage == null || editPage == null)
  293. return;
  294. if (ToolView.CurrentEditAreaObject() != null)
  295. {
  296. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathAreas[0].GetFrame());
  297. if (pathAreas[0].Rotate((int)e))
  298. {
  299. PDFEditHistory editHistory = new PDFEditHistory();
  300. editHistory.EditPage = editPage;
  301. editHistory.PageIndex = pdfPage.PageIndex;
  302. ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
  303. ToolView.UpdateRender(oldRect, pathAreas[0]);
  304. }
  305. }
  306. else
  307. {
  308. GroupHistory groupHistory = new GroupHistory();
  309. foreach (CPDFEditPathArea pathArea in pathAreas)
  310. {
  311. if (pathArea.Rotate((int)e))
  312. {
  313. PDFEditHistory editHistory = new PDFEditHistory();
  314. editHistory.EditPage = editPage;
  315. editHistory.PageIndex = pdfPage.PageIndex;
  316. groupHistory.Histories.Add(editHistory);
  317. }
  318. }
  319. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
  320. ToolView.GetCPDFViewer()?.UpdateRenderFrame();
  321. }
  322. editPage.EndEdit();
  323. RotationTxb.Text = pathAreas.FirstOrDefault().GetRotation().ToString();
  324. }
  325. private void Slider_DragStarted(object sender, DragStartedEventArgs e)
  326. {
  327. Slider slider = sender as Slider;
  328. if (slider != null)
  329. {
  330. slider.Tag = "false";
  331. }
  332. }
  333. private void SliderOpacity_DragCompleted(object sender, DragCompletedEventArgs e)
  334. {
  335. Slider slider = sender as Slider;
  336. if (slider != null)
  337. {
  338. slider.Tag = "true";
  339. }
  340. GetPathArea(out List<CPDFEditPathArea> pathAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
  341. if (pathAreas.Count == 0 || pdfPage == null || editPage == null)
  342. return;
  343. if (ToolView.CurrentEditAreaObject() != null)
  344. {
  345. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathAreas[0].GetFrame());
  346. if (pathAreas[0].SetTransparency((byte)(PathOpacitySlider.Value * 255)))
  347. {
  348. PDFEditHistory editHistory = new PDFEditHistory();
  349. editHistory.EditPage = editPage;
  350. editHistory.PageIndex = pdfPage.PageIndex;
  351. ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
  352. ToolView.UpdateRender(oldRect, pathAreas[0]);
  353. }
  354. }
  355. else
  356. {
  357. GroupHistory groupHistory = new GroupHistory();
  358. foreach (CPDFEditPathArea pathArea in pathAreas)
  359. {
  360. if (pathArea.SetTransparency((byte)(PathOpacitySlider.Value * 255)))
  361. {
  362. PDFEditHistory editHistory = new PDFEditHistory();
  363. editHistory.EditPage = editPage;
  364. editHistory.PageIndex = pdfPage.PageIndex;
  365. groupHistory.Histories.Add(editHistory);
  366. }
  367. }
  368. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
  369. ToolView.GetCPDFViewer()?.UpdateRenderFrame();
  370. }
  371. editPage.EndEdit();
  372. }
  373. private void SliderOpacity_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
  374. {
  375. Slider slider = sender as Slider;
  376. if (OpacityTextBox != null)
  377. {
  378. OpacityTextBox.Text = string.Format("{0}%", (int)(PathOpacitySlider.Value * 100));
  379. }
  380. if (slider != null && slider.Tag != null && slider.Tag.ToString() == "false")
  381. {
  382. return;
  383. }
  384. GetPathArea(out List<CPDFEditPathArea> pathAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
  385. if (pathAreas.Count == 0 || pdfPage == null || editPage == null)
  386. return;
  387. if (ToolView.CurrentEditAreaObject() != null)
  388. {
  389. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathAreas[0].GetFrame());
  390. if (pathAreas[0].SetTransparency((byte)(PathOpacitySlider.Value * 255)))
  391. {
  392. PDFEditHistory editHistory = new PDFEditHistory();
  393. editHistory.EditPage = editPage;
  394. editHistory.PageIndex = pdfPage.PageIndex;
  395. ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
  396. ToolView.UpdateRender(oldRect, pathAreas[0]);
  397. }
  398. }
  399. else
  400. {
  401. GroupHistory groupHistory = new GroupHistory();
  402. foreach (CPDFEditPathArea pathArea in pathAreas)
  403. {
  404. if (pathArea.SetTransparency((byte)(PathOpacitySlider.Value * 255)))
  405. {
  406. PDFEditHistory editHistory = new PDFEditHistory();
  407. editHistory.EditPage = editPage;
  408. editHistory.PageIndex = pdfPage.PageIndex;
  409. groupHistory.Histories.Add(editHistory);
  410. }
  411. }
  412. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
  413. ToolView.GetCPDFViewer()?.UpdateRenderFrame();
  414. }
  415. editPage.EndEdit();
  416. }
  417. private void PathClipBtn_Click(object sender, RoutedEventArgs e)
  418. {
  419. ToolView.SetCropMode(!ToolView.GetIsCropMode());
  420. }
  421. private void OpacityComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  422. {
  423. ComboBoxItem selectItem = OpacityComboBox.SelectedItem as ComboBoxItem;
  424. if (selectItem != null && selectItem.Content != null)
  425. {
  426. if (double.TryParse(selectItem.Content.ToString().TrimEnd('%'), out double newOpacity))
  427. {
  428. OpacityTextBox.Text = selectItem.Content.ToString();
  429. PathOpacitySlider.Value = newOpacity / 100.0;
  430. }
  431. }
  432. }
  433. private void GetPathArea(out List<CPDFEditPathArea> pathAreas, out CPDFPage pdfPage, out CPDFEditPage editPage)
  434. {
  435. pathAreas = new List<CPDFEditPathArea>();
  436. editPage = null;
  437. pdfPage = null;
  438. if (ToolView == null || EditEvents.Count == 0)
  439. {
  440. return;
  441. }
  442. try
  443. {
  444. foreach (var EditEvent in EditEvents)
  445. {
  446. CPDFViewer pdfViewer = ToolView.GetCPDFViewer();
  447. CPDFDocument pdfDoc = pdfViewer.GetDocument();
  448. pdfPage = pdfDoc.PageAtIndex(EditEvent.PageIndex);
  449. editPage = pdfPage.GetEditPage();
  450. List<CPDFEditArea> editAreas = editPage.GetEditAreaList();
  451. if (editAreas != null && editAreas.Count > EditEvent.EditIndex)
  452. {
  453. pathAreas.Add(editAreas[EditEvent.EditIndex] as CPDFEditPathArea);
  454. }
  455. }
  456. }
  457. catch (Exception ex)
  458. {
  459. }
  460. }
  461. private void SetAbsRotation(double absRotation)
  462. {
  463. GetPathArea(out List<CPDFEditPathArea> pathAreas, out CPDFPage pdfPage, out CPDFEditPage editPage);
  464. if (pathAreas.Count == 0 || pdfPage == null || editPage == null)
  465. return;
  466. if (ToolView.CurrentEditAreaObject() != null)
  467. {
  468. Rect oldRect = DataConversionForWPF.CRectConversionForRect(pathAreas[0].GetFrame());
  469. int rotation = (int)absRotation - pathAreas[0].GetRotation();
  470. if (pathAreas[0].Rotate(rotation))
  471. {
  472. PDFEditHistory editHistory = new PDFEditHistory();
  473. editHistory.EditPage = editPage;
  474. editHistory.PageIndex = pdfPage.PageIndex;
  475. ToolView.GetCPDFViewer().UndoManager.AddHistory(editHistory);
  476. ToolView.UpdateRender(oldRect, pathAreas[0]);
  477. }
  478. }
  479. else
  480. {
  481. GroupHistory groupHistory = new GroupHistory();
  482. foreach (CPDFEditPathArea pathArea in pathAreas)
  483. {
  484. int rotation = (int)absRotation - pathArea.GetRotation();
  485. if (pathArea.Rotate(rotation))
  486. {
  487. PDFEditHistory editHistory = new PDFEditHistory();
  488. editHistory.EditPage = editPage;
  489. editHistory.PageIndex = pdfPage.PageIndex;
  490. groupHistory.Histories.Add(editHistory);
  491. }
  492. }
  493. ToolView.GetCPDFViewer()?.UndoManager.AddHistory(groupHistory);
  494. ToolView.GetCPDFViewer()?.UpdateRenderFrame();
  495. }
  496. editPage.EndEdit();
  497. }
  498. private void RotationTxb_LostFocus(object sender, RoutedEventArgs e)
  499. {
  500. if (!double.TryParse(RotationTxb.Text, out double rotation))
  501. {
  502. return;
  503. }
  504. SetAbsRotation(rotation);
  505. }
  506. private void RotationTxb_PreviewKeyDown(object sender, KeyEventArgs e)
  507. {
  508. if (e.Key == Key.Enter)
  509. {
  510. RotationTxb_LostFocus(null, null);
  511. }
  512. }
  513. #endregion
  514. public event PropertyChangedEventHandler PropertyChanged;
  515. protected bool UpdateProper<T>(ref T properValue,
  516. T newValue,
  517. [CallerMemberName] string properName = "")
  518. {
  519. if (object.Equals(properValue, newValue))
  520. return false;
  521. properValue = newValue;
  522. OnPropertyChanged(properName);
  523. return true;
  524. }
  525. protected void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
  526. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  527. }
  528. }