BackgroundTemplateListFileContent.xaml.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using PDF_Master.ViewModels.EditTools.Background;
  2. using PDFSettings;
  3. using System.Diagnostics;
  4. using System;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Media.Imaging;
  8. using System.IO;
  9. namespace PDF_Master.Views.EditTools.Background
  10. {
  11. /// <summary>
  12. /// Interaction logic for BackgroundTemplateListFileContent
  13. /// </summary>
  14. public partial class BackgroundTemplateListFileContent : UserControl
  15. {
  16. private BackgroundTemplateListFileContentViewModel viewModel;
  17. public BackgroundTemplateListFileContent()
  18. {
  19. InitializeComponent();
  20. viewModel = this.DataContext as BackgroundTemplateListFileContentViewModel;
  21. }
  22. private void DeleteTemplateBtn_Click(object sender, System.Windows.RoutedEventArgs e)
  23. {
  24. viewModel.DeleteTemplateItemCommand?.Execute(sender);
  25. }
  26. private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
  27. {
  28. var listBox = sender as ListBox;
  29. viewModel.SelectTemplateItemCommand?.Execute(sender);
  30. //listBox.SelectedIndex = -1;
  31. }
  32. private void MenuEdit_Click(object sender, RoutedEventArgs e)
  33. {
  34. viewModel.EditTemplateItemCommand?.Execute(sender);
  35. }
  36. private void MenuDeleteCurrent_Click(object sender, RoutedEventArgs e)
  37. {
  38. viewModel.DeleteTemplateItemCommand?.Execute(sender);
  39. }
  40. private void MenuDeleteAll_Click(object sender, RoutedEventArgs e)
  41. {
  42. viewModel.DeleteAllTemplateItemCommand?.Execute();
  43. }
  44. private void EditTemplateBtn_Click(object sender, RoutedEventArgs e)
  45. {
  46. viewModel.EditTemplateItemCommand?.Execute(sender);
  47. }
  48. private void itemPanel_Loaded(object sender, RoutedEventArgs e)
  49. {
  50. try
  51. {
  52. StackPanel panel = sender as StackPanel;
  53. var data = panel.DataContext as BackgroundItem;
  54. var img = panel.FindName("BackgroundPreview") as Image;
  55. Trace.WriteLine(data.previewImagePath);
  56. if (!string.IsNullOrEmpty(data.previewImagePath) && File.Exists(data.previewImagePath))
  57. {
  58. BitmapSource bmp = new BitmapImage(new Uri(data.previewImagePath));
  59. img.Source = bmp;
  60. }
  61. }
  62. catch { }
  63. }
  64. }
  65. }