using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Printing;

namespace Bildbetrachter
{
    /// <summary>
    /// Interaktionslogik für MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        List<BitmapImage> images;

        public MainWindow()
        {
            InitializeComponent();

            images = new List<BitmapImage>();
            images.Add(new BitmapImage(new Uri("Schottland01.jpg", UriKind.Relative)));
            images.Add(new BitmapImage(new Uri("Schottland02.jpg", UriKind.Relative)));
            images.Add(new BitmapImage(new Uri("Schottland03.jpg", UriKind.Relative)));
            images.Add(new BitmapImage(new Uri("Schottland04.jpg", UriKind.Relative)));
            images.Add(new BitmapImage(new Uri("Schottland05.jpg", UriKind.Relative)));


            thumbNail1.Source = images[0];
            thumbNail2.Source = images[1];
            thumbNail3.Source = images[2];
            thumbNail4.Source = images[3];
            thumbNail5.Source = images[4];
        }

        private void thumbNail_MouseEnter(object sender, MouseEventArgs e)
        {
            Image img = sender as Image;

            if (img != null)
            {
                if (img.Name == "thumbNail1")
                    bigImage.Source = images[0];
                if (img.Name == "thumbNail2")
                    bigImage.Source = images[1];
                if (img.Name == "thumbNail3")
                    bigImage.Source = images[2];
                if (img.Name == "thumbNail4")
                    bigImage.Source = images[3];
                if (img.Name == "thumbNail5")
                    bigImage.Source = images[4];
            }

        }

        private void cmiPrint_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog printDlg = new System.Windows.Controls.PrintDialog();

            if (printDlg.ShowDialog() == true)
            {
                // Druckerfähigkeiten abfragen
                PrintCapabilities pc = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket);
                Size paperSize = new Size(pc.PageImageableArea.ExtentWidth, pc.PageImageableArea.ExtentHeight);

                // Skalierungsfaktor unter Beibehaltung der aktuellen Proportionen berechnen
                double scale = Math.Min(paperSize.Width  / bigImage.ActualWidth,
                                        paperSize.Height / bigImage.ActualHeight);

                // das zu druckende Steuerelement skalieren
                bigImage.LayoutTransform = new ScaleTransform(scale, scale);
                bigImage.Measure(paperSize);
                bigImage.Arrange(new Rect(new Point(pc.PageImageableArea.OriginWidth, pc.PageImageableArea.OriginHeight), paperSize));

                // drucken
                printDlg.PrintVisual(bigImage, "Ausdruck");
            }
        }

    }
}
