// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2014 OxyPlot contributors // // // Interaction logic for MainWindow.xaml // // -------------------------------------------------------------------------------------------------------------------- namespace WpfExamples { using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Windows; using System.Windows.Controls; using System.Windows.Input; /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow { /// /// Initializes a new instance of the class. /// public MainWindow() { InitializeComponent(); this.DataContext = this; this.Examples = this.GetExamples(this.GetType().Assembly).OrderBy(e => e.Title).ToArray(); } /// /// Gets the examples. /// /// The examples. public IList Examples { get; private set; } /// /// Creates a thumbnail of the specified window. /// /// The window. /// The width of the thumbnail. /// The output path. private static void CreateThumbnail(Window window, int width, string path) { var bitmap = ScreenCapture.Capture( (int)window.Left, (int)window.Top, (int)window.ActualWidth, (int)window.ActualHeight); var newHeight = width * bitmap.Height / bitmap.Width; var resizedBitmap = BitmapTools.Resize(bitmap, width, newHeight); resizedBitmap.Save(path); } /// /// Handles the MouseDoubleClick event of the ListBox control. /// /// The source of the event. /// The instance containing the event data. private void ListBoxMouseDoubleClick(object sender, MouseButtonEventArgs e) { var lb = (ListBox)sender; var example = lb.SelectedItem as Example; if (example != null) { var window = example.Create(); window.Icon = this.Icon; window.Show(); window.KeyDown += (s, args) => { if (args.Key == Key.F12) { CreateThumbnail(window, 120, Path.Combine(@"..\..\Images\", example.ThumbnailFileName)); MessageBox.Show(window, "Demo image updated."); e.Handled = true; } }; } } /// /// Gets the examples in the specified assembly. /// /// The assembly to scan. /// A sequence of objects. private IEnumerable GetExamples(Assembly assembly) { foreach (var type in assembly.GetTypes()) { var ea = type.GetCustomAttributes(typeof(ExampleAttribute), false).FirstOrDefault() as ExampleAttribute; if (ea != null) { yield return new Example(type, ea.Title, ea.Description); } } } } }