QuickToolsContentViewModel.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. using ComPDFKitViewer.PdfViewer;
  2. using Microsoft.Office.Core;
  3. using PDF_Master.CustomControl;
  4. using PDF_Master.Helper;
  5. using PDF_Master.Model;
  6. using PDF_Master.Model.Dialog.ConverterDialogs;
  7. using PDF_Master.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  8. using PDF_Master.Model.Dialog.ToolsDialogs;
  9. using PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs;
  10. using PDF_Master.Model.PDFTool;
  11. using PDF_Master.Properties;
  12. using PDF_Master.Views;
  13. using PDFSettings;
  14. using Prism.Commands;
  15. using Prism.Mvvm;
  16. using Prism.Regions;
  17. using Prism.Services.Dialogs;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using System.Windows.Controls;
  24. using static PDF_Master.Model.Dialog.ToolsDialogs.SaftyDialogs.DeleteSafetySettintgsModel;
  25. namespace PDF_Master.ViewModels.HomePanel.PDFTools
  26. {
  27. public class QuickToolsContentViewModel : BindableBase
  28. {
  29. #region 文案
  30. private string T_title;
  31. public string T_Title
  32. {
  33. get { return T_title; }
  34. set
  35. {
  36. SetProperty(ref T_title, value);
  37. }
  38. }
  39. private void InitString()
  40. {
  41. T_Title = App.HomePageLoader.GetString("HomeTool_Title");
  42. }
  43. #endregion
  44. #region 属性
  45. /// <summary>
  46. /// 扩展/收缩 默认展开
  47. /// </summary>
  48. private bool _isExpendTools = true;
  49. public bool IsExpendTools
  50. {
  51. get { return _isExpendTools; }
  52. set { SetProperty(ref _isExpendTools, value); }
  53. }
  54. private string regionName;
  55. public string ToolRegionName
  56. {
  57. get { return regionName; }
  58. set { SetProperty(ref regionName, value); }
  59. }
  60. #endregion
  61. #region Command and Event
  62. public IDialogService dialogs;
  63. public DelegateCommand<ToolItem> QuickToolsCommand { get; set; }
  64. public DelegateCommand<object> OpenMenuCommand { get; set; }
  65. public DelegateCommand ExpendCommand { get; set; }
  66. public DelegateCommand ShowToolCommand { get; set; }
  67. public IRegionManager toolregion;
  68. public event EventHandler<bool> ExpendToolsHanlder;
  69. #endregion
  70. public QuickToolsContentViewModel(IDialogService dialogService, IRegionManager regionManager)
  71. {
  72. toolregion = regionManager;
  73. ToolRegionName = RegionNames.ToolRegionName;
  74. System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  75. {
  76. toolregion.RequestNavigate(ToolRegionName, "Guid");
  77. }));
  78. dialogs = dialogService;
  79. InitVariable();
  80. InitCommand();
  81. InitString();
  82. }
  83. #region 初始化和绑定
  84. private void InitVariable()
  85. {
  86. }
  87. private void InitCommand()
  88. {
  89. QuickToolsCommand = new DelegateCommand<ToolItem>(QuickTools_Click);
  90. OpenMenuCommand = new DelegateCommand<object>(OpenMenu);
  91. ExpendCommand = new DelegateCommand(Expend);
  92. ShowToolCommand = new DelegateCommand(ShowTool);
  93. }
  94. #endregion
  95. private void ShowTool()
  96. {
  97. toolregion.RequestNavigate(ToolRegionName, "Tools");
  98. }
  99. public void QuickTools_Click(ToolItem toolItem)
  100. {
  101. /*
  102. *设置这个对话框的起始保存路径
  103. */
  104. System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
  105. dlg.Multiselect = false;
  106. dlg.Filter = "PDF|*.pdf;*.PDF;";
  107. //MVP原规划的批量工具 暂时先注释掉
  108. //if (toolItem.FnType == PDFFnType.Compress || toolItem.FnType == PDFFnType.Security||
  109. // toolItem.FnType ==PDFFnType.BatchRemove||toolItem.FnType==PDFFnType.ConvertPDF||
  110. // toolItem.FnType==PDFFnType.Background|| toolItem.FnType == PDFFnType.HeaderFooter||
  111. // toolItem.FnType == PDFFnType.BatesNumbers|| toolItem.FnType == PDFFnType.WaterMark||
  112. // toolItem.FnType == PDFFnType.PDFToExcel|| toolItem.FnType == PDFFnType.PDFToImage||
  113. // toolItem.FnType == PDFFnType.PDFToPPT|| toolItem.FnType == PDFFnType.Batch ||
  114. // toolItem.FnType == PDFFnType.Merge)
  115. //{
  116. // //dlg.Multiselect = true;
  117. //}
  118. if (toolItem.FnType == PDFFnType.ImageToPDF)
  119. {
  120. dlg.Multiselect = true;
  121. dlg.Filter = "Picture|*.png;*.jpg;*bmp;*jpeg;*gif;*tiff;";
  122. }
  123. else if(toolItem.FnType == PDFFnType.Merge)
  124. {
  125. dlg.Multiselect = true;
  126. dlg.Filter = Properties.Resources.imageex.ToLower() + "|*";
  127. }
  128. //付费锁 图片转PDF不用加锁
  129. if (toolItem.FnType != PDFFnType.ImageToPDF&&(!App.IsLogin || Settings.Default.UserDate.isInFreeUseTime == false) )
  130. {
  131. dialogs.ShowDialog(DialogNames.IAPCompareDialog);
  132. return ;
  133. }
  134. if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  135. {
  136. CPDFViewer viewer = new CPDFViewer();
  137. switch ((PDFFnType)toolItem.FnType)
  138. {
  139. case PDFFnType.Split:
  140. viewer.InitDocument(dlg.FileName);
  141. if (!CheckPassword(viewer)) {return;}
  142. DialogParameters splitvalue = new DialogParameters();
  143. splitvalue.Add(ParameterNames.PDFViewer, viewer);
  144. splitvalue.Add(ParameterNames.FilePath, dlg.FileName);
  145. dialogs.ShowDialog(DialogNames.HomePageSplitDialog, splitvalue, e => { });
  146. break;
  147. case PDFFnType.Extract:
  148. viewer.InitDocument(dlg.FileName);
  149. if (!CheckPassword(viewer)) {return;}
  150. DialogParameters extractvalue = new DialogParameters();
  151. extractvalue.Add(ParameterNames.PDFViewer, viewer);
  152. extractvalue.Add(ParameterNames.FilePath, dlg.FileName);
  153. dialogs.ShowDialog(DialogNames.HomePageExtractDialog, extractvalue, e => { });
  154. break;
  155. case PDFFnType.Insert:
  156. viewer.InitDocument(dlg.FileName);
  157. if (!CheckPassword(viewer)) {return;}
  158. DialogParameters insertvalue = new DialogParameters();
  159. insertvalue.Add(ParameterNames.PDFViewer, viewer);
  160. insertvalue.Add(ParameterNames.FilePath, dlg.FileName);
  161. dialogs.ShowDialog(DialogNames.HomePageInsertDialog, insertvalue, e => { });
  162. break;
  163. case PDFFnType.Compress:
  164. viewer.InitDocument(dlg.FileName);
  165. if (!CheckPassword(viewer)) { return; }
  166. DialogParameters compresspdf = new DialogParameters();
  167. compresspdf.Add(ParameterNames.PDFViewer, viewer);
  168. dialogs.ShowDialog(DialogNames.CompressDialog, compresspdf, e =>
  169. {
  170. CompressDialogModel compressDialogModel = new CompressDialogModel();
  171. compressDialogModel.OnOpened((Prism.Services.Dialogs.DialogResult)e);
  172. // OnOpened((Prism.Services.Dialogs.DialogResult)e);
  173. });
  174. //批量
  175. //DialogParameters compresspdf = new DialogParameters();
  176. //compresspdf.Add(ParameterNames.BatchProcessing_Name, "1");
  177. //HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  178. //HomePageBatchProcessingDialogModel.BatchProcessingIndex = 1;
  179. //compresspdf.Add(ParameterNames.FilePath, dlg.FileNames);
  180. //dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, compresspdf, e => { });
  181. break;
  182. case PDFFnType.ImageToPDF:
  183. DialogParameters picturetopdf = new DialogParameters();
  184. picturetopdf.Add(ParameterNames.FilePath, dlg.FileNames);
  185. dialogs.ShowDialog(DialogNames.HomePagePictureToPDFDialog, picturetopdf, e => { });
  186. break;
  187. case PDFFnType.Print:
  188. viewer.InitDocument(dlg.FileName);
  189. if (!CheckPassword(viewer)) {return;}
  190. DialogParameters printvalue = new DialogParameters();
  191. printvalue.Add(ParameterNames.PDFViewer, viewer);
  192. printvalue.Add(ParameterNames.FilePath, dlg.FileName);
  193. dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printvalue, e => { });
  194. try
  195. {
  196. dialogs.ShowDialog("MainWindow");
  197. }
  198. catch
  199. {
  200. }
  201. break;
  202. case PDFFnType.Security:
  203. //DialogParameters securitypdf = new DialogParameters();
  204. //securitypdf.Add(ParameterNames.BatchProcessing_Name, "2");
  205. //HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  206. //HomePageBatchProcessingDialogModel.BatchProcessingIndex = 2;
  207. //securitypdf.Add(ParameterNames.FilePath, dlg.FileNames);
  208. //dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, securitypdf, e => { });
  209. CPDFViewer cPDFViewer = new CPDFViewer();
  210. cPDFViewer.InitDocument(dlg.FileName);
  211. if (cPDFViewer.Document == null) {
  212. AlertsMessage alertsMessage = new AlertsMessage();
  213. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_OpenFileFailedWarning"), App.ServiceLoader.GetString("Text_ok"));
  214. return ;
  215. }
  216. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(cPDFViewer.Document, EnumPasswordKind.StatusPermissionsPassword, dialogs);
  217. if (result.IsDiscryptied)
  218. {
  219. if (result.Password != null)
  220. {
  221. cPDFViewer.Document.UnlockWithPassword(result.Password);
  222. }
  223. ///TODO:
  224. ///此处填入需要执行的代码
  225. ///
  226. DialogParameters param = new DialogParameters();
  227. param.Add(ParameterNames.PDFViewer, cPDFViewer);
  228. dialogs.ShowDialog(DialogNames.SetPasswordDialog, param, e => {
  229. string FilePath;
  230. if (e.Parameters.TryGetValue("FilePath",out FilePath))
  231. {
  232. CommonHelper.ShowFileBrowser(FilePath);
  233. }
  234. });
  235. }
  236. break;
  237. case PDFFnType.ConvertPDF:
  238. //DialogParameters convertpdf = new DialogParameters();
  239. //convertpdf.Add(ParameterNames.BatchProcessing_Name, "0");
  240. //HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  241. //HomePageBatchProcessingDialogModel.BatchProcessingIndex = 0;
  242. //convertpdf.Add(ParameterNames.FilePath, dlg.FileNames);
  243. //dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, convertpdf, e => { });
  244. break;
  245. case PDFFnType.BatchRemove:
  246. DialogParameters batchremovepdf = new DialogParameters();
  247. batchremovepdf.Add(ParameterNames.BatchProcessing_Name, "7");
  248. HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  249. HomePageBatchProcessingDialogModel.BatchProcessingIndex = 7;
  250. batchremovepdf.Add(ParameterNames.FilePath, dlg.FileNames);
  251. dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, batchremovepdf, e => { });
  252. break;
  253. case PDFFnType.HeaderFooter:
  254. DialogParameters headerFooterpdf = new DialogParameters();
  255. headerFooterpdf.Add(ParameterNames.BatchProcessing_Name, "5");
  256. HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  257. HomePageBatchProcessingDialogModel.BatchProcessingIndex = 5;
  258. headerFooterpdf.Add(ParameterNames.FilePath, dlg.FileNames);
  259. dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, headerFooterpdf, e => { });
  260. break;
  261. case PDFFnType.BatesNumbers:
  262. DialogParameters batesNumberspdf = new DialogParameters();
  263. batesNumberspdf.Add(ParameterNames.BatchProcessing_Name, "6");
  264. HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  265. HomePageBatchProcessingDialogModel.BatchProcessingIndex = 6;
  266. batesNumberspdf.Add(ParameterNames.FilePath, dlg.FileNames);
  267. dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, batesNumberspdf, e => { });
  268. break;
  269. case PDFFnType.Background:
  270. DialogParameters backgroundpdf = new DialogParameters();
  271. backgroundpdf.Add(ParameterNames.BatchProcessing_Name, "4");
  272. HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  273. HomePageBatchProcessingDialogModel.BatchProcessingIndex = 4;
  274. backgroundpdf.Add(ParameterNames.FilePath, dlg.FileNames);
  275. dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, backgroundpdf, e => { });
  276. break;
  277. case PDFFnType.WaterMark:
  278. DialogParameters watermarkpdf = new DialogParameters();
  279. watermarkpdf.Add(ParameterNames.BatchProcessing_Name, "3");
  280. HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  281. HomePageBatchProcessingDialogModel.BatchProcessingIndex = 3;
  282. watermarkpdf.Add(ParameterNames.FilePath, dlg.FileNames);
  283. dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, watermarkpdf, e => { });
  284. break;
  285. case PDFFnType.PDFToImage:
  286. viewer.InitDocument(dlg.FileName);
  287. if (!CheckPassword(viewer)) { return; }
  288. DialogParameters convertpdftoimage = new DialogParameters();
  289. convertpdftoimage.Add("PageRangeComboBoxCurrentPage", true);
  290. convertpdftoimage.Add(ParameterNames.PDFViewer, viewer);
  291. dialogs.ShowDialog(DialogNames.ConverterImgDialog, convertpdftoimage, e =>
  292. {
  293. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  294. converterDialogsModel.OnOpened((DialogResult)e);
  295. });
  296. //DialogParameters convertpdftoimage = new DialogParameters();
  297. //convertpdftoimage.Add(ParameterNames.BatchProcessing_Name, "0");
  298. //convertpdftoimage.Add("ConverterTypeIndex", 7);
  299. //HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  300. //HomePageBatchProcessingDialogModel.BatchProcessingIndex = 0;
  301. //convertpdftoimage.Add(ParameterNames.FilePath, dlg.FileNames);
  302. //dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, convertpdftoimage, e => { });
  303. break;
  304. case PDFFnType.PDFToExcel:
  305. viewer.InitDocument(dlg.FileName);
  306. if (!CheckPassword(viewer)) { return; }
  307. DialogParameters convertpdftoexcel = new DialogParameters();
  308. convertpdftoexcel.Add(ParameterNames.PDFViewer, viewer);
  309. convertpdftoexcel.Add("PageRangeComboBoxCurrentPage", true);
  310. dialogs.ShowDialog(DialogNames.ConverterExcelDialog, convertpdftoexcel, e =>
  311. {
  312. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  313. converterDialogsModel.OnOpened((DialogResult)e);
  314. });
  315. //DialogParameters convertpdftoexcel = new DialogParameters();
  316. //convertpdftoexcel.Add(ParameterNames.BatchProcessing_Name, "0");
  317. //convertpdftoexcel.Add("ConverterTypeIndex", 1);
  318. //HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  319. //HomePageBatchProcessingDialogModel.BatchProcessingIndex = 0;
  320. //convertpdftoexcel.Add(ParameterNames.FilePath, dlg.FileNames);
  321. //dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, convertpdftoexcel, e => { });
  322. break;
  323. case PDFFnType.PDFToPPT:
  324. viewer.InitDocument(dlg.FileName);
  325. if (!CheckPassword(viewer)) { return; }
  326. DialogParameters convertpdftoPPT = new DialogParameters();
  327. convertpdftoPPT.Add(ParameterNames.PDFViewer, viewer);
  328. convertpdftoPPT.Add("PageRangeComboBoxCurrentPage", true);
  329. dialogs.ShowDialog(DialogNames.ConverterPPTDialog, convertpdftoPPT, e =>
  330. {
  331. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  332. converterDialogsModel.OnOpened((DialogResult)e);
  333. });
  334. //批量处理
  335. //DialogParameters convertpdftoppt = new DialogParameters();
  336. //convertpdftoppt.Add(ParameterNames.BatchProcessing_Name, "0");
  337. //convertpdftoppt.Add("ConverterTypeIndex", 2);
  338. //HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  339. //HomePageBatchProcessingDialogModel.BatchProcessingIndex = 0;
  340. //convertpdftoppt.Add(ParameterNames.FilePath, dlg.FileNames);
  341. //dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, convertpdftoppt, e => { });
  342. break;
  343. case PDFFnType.PDFToWord:
  344. viewer.InitDocument(dlg.FileName);
  345. if (!CheckPassword(viewer)) { return; }
  346. DialogParameters convertpdftoword = new DialogParameters();
  347. convertpdftoword.Add(ParameterNames.PDFViewer, viewer);
  348. convertpdftoword.Add("PageRangeComboBoxCurrentPage", true);
  349. dialogs.ShowDialog(DialogNames.ConverterWordDialog, convertpdftoword, e =>
  350. {
  351. ConverterDialogsModel converterDialogsModel = new ConverterDialogsModel();
  352. converterDialogsModel.OnOpened((DialogResult)e);
  353. });
  354. //批量处理
  355. //DialogParameters convertpdftoword = new DialogParameters();
  356. //convertpdftoword.Add(ParameterNames.BatchProcessing_Name, "0");
  357. //convertpdftoword.Add("ConverterTypeIndex", 0);
  358. //HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  359. //HomePageBatchProcessingDialogModel.BatchProcessingIndex = 0;
  360. //convertpdftoword.Add(ParameterNames.FilePath, dlg.FileNames);
  361. //dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, convertpdftoword, e => { });
  362. break;
  363. case PDFFnType.Batch:
  364. DialogParameters batcpdf = new DialogParameters();
  365. batcpdf.Add(ParameterNames.BatchProcessing_Name, "0");
  366. HomePageBatchProcessingDialogModel.FilePaths = dlg.FileNames.ToList();
  367. HomePageBatchProcessingDialogModel.BatchProcessingIndex = 0;
  368. batcpdf.Add(ParameterNames.FilePath, dlg.FileNames);
  369. dialogs.ShowDialog(DialogNames.HomePageBatchProcessingDialog, batcpdf, e => { });
  370. break;
  371. case PDFFnType.Merge:
  372. viewer.InitDocument(dlg.FileName);
  373. // if (!CheckPassword(viewer)) { return; }
  374. DialogParameters merge = new DialogParameters();
  375. merge.Add(ParameterNames.PDFViewer, viewer);
  376. merge.Add(ParameterNames.FilePath, dlg.FileNames);
  377. dialogs.ShowDialog(DialogNames.MergeDialog, merge, e =>
  378. {
  379. });
  380. break;
  381. }
  382. }
  383. }
  384. //
  385. //
  386. private bool CheckPassword(CPDFViewer viewer) {
  387. if (viewer.Document == null)
  388. {
  389. AlertsMessage alertsMessage = new AlertsMessage();
  390. alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_OpenFileFailedWarning"), App.ServiceLoader.GetString("Text_ok"));
  391. return false;
  392. }
  393. if (viewer.Document.IsLocked)
  394. {
  395. VerifyPasswordResult result = SecurityHelper.VerifyPasswordByPasswordKind(viewer.Document, EnumPasswordKind.StatusOpenPassword, dialogs);
  396. if (result.IsDiscryptied)
  397. {
  398. if (result.Password != null)
  399. {
  400. if(viewer.Document.UnlockWithPassword(result.Password))
  401. {
  402. //if (viewer.Document.CheckOwnerPassword(result.Password))
  403. //{
  404. viewer.Tag = result.Password;
  405. //}
  406. }
  407. }
  408. ///TODO:
  409. ///此处填入需要执行的代码
  410. }
  411. if (result.IsDiscryptied == false)
  412. {
  413. //未成功解密文档时,释放Document对象,返回
  414. viewer.Document.Release();
  415. return false;
  416. }
  417. }
  418. return true;
  419. }
  420. private void Expend()
  421. {
  422. IsExpendTools = !IsExpendTools;
  423. ExpendToolsHanlder?.Invoke(null, IsExpendTools);
  424. }
  425. private void OpenMenu(object obj)
  426. {
  427. var menu = App.Current.FindResource("ExpendToolsContextMenu") as ContextMenu;
  428. var btn = obj as Button;
  429. if (menu != null && btn != null)
  430. {
  431. if(menu.Items.Count == 1)
  432. {
  433. var item = menu.Items[0] as MenuItem;
  434. if(_isExpendTools)
  435. {
  436. item.Header = "Collapse";
  437. }
  438. else
  439. {
  440. item.Header = "Expand";
  441. }
  442. item.Command = ExpendCommand;
  443. //btn.ContextMenu = menu;
  444. menu.PlacementTarget = btn;
  445. menu.IsOpen = true;
  446. }
  447. }
  448. }
  449. }
  450. }