using PDF_Master.ViewModels.EditTools.Background; using PDFSettings; using System.Diagnostics; using System; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; using System.IO; namespace PDF_Master.Views.EditTools.Background { /// /// Interaction logic for BackgroundTemplateListFileContent /// public partial class BackgroundTemplateListFileContent : UserControl { private BackgroundTemplateListFileContentViewModel viewModel; public BackgroundTemplateListFileContent() { InitializeComponent(); viewModel = this.DataContext as BackgroundTemplateListFileContentViewModel; } private void DeleteTemplateBtn_Click(object sender, System.Windows.RoutedEventArgs e) { viewModel.DeleteTemplateItemCommand?.Execute(sender); } private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { var listBox = sender as ListBox; viewModel.SelectTemplateItemCommand?.Execute(sender); //listBox.SelectedIndex = -1; } private void MenuEdit_Click(object sender, RoutedEventArgs e) { viewModel.EditTemplateItemCommand?.Execute(sender); } private void MenuDeleteCurrent_Click(object sender, RoutedEventArgs e) { viewModel.DeleteTemplateItemCommand?.Execute(sender); } private void MenuDeleteAll_Click(object sender, RoutedEventArgs e) { viewModel.DeleteAllTemplateItemCommand?.Execute(); } private void EditTemplateBtn_Click(object sender, RoutedEventArgs e) { viewModel.EditTemplateItemCommand?.Execute(sender); } private void itemPanel_Loaded(object sender, RoutedEventArgs e) { try { StackPanel panel = sender as StackPanel; var data = panel.DataContext as BackgroundItem; var img = panel.FindName("BackgroundPreview") as Image; Trace.WriteLine(data.previewImagePath); if (!string.IsNullOrEmpty(data.previewImagePath) && File.Exists(data.previewImagePath)) { BitmapSource bmp = new BitmapImage(new Uri(data.previewImagePath)); img.Source = bmp; } } catch { } } } }