using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace PdfViewerSamples
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class AnnotationDemo : UserControl
    {
        public AnnotationDemo()
        {
            this.InitializeComponent();
            this.Loaded += AnnotationDemo_Loaded;
            this.Unloaded += AnnotationDemo_Unloaded;
           
        }

        void AnnotationDemo_Unloaded(object sender, RoutedEventArgs e)
        {
            pdfViewer.CloseDocument();
        }

        void AnnotationDemo_Loaded(object sender, RoutedEventArgs e)
        {
            Assembly asm = typeof(AnnotationDemo).GetTypeInfo().Assembly;
            Stream stream = asm.GetManifestResourceStream("PdfViewerSamples.Files.CorporateProfile.pdf");
            pdfViewer.LoadDocument(stream);
        }

        private async void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.FileTypeFilter.Add(".pdf");

            StorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                Stream stream = await file.OpenStreamForReadAsync();
                pdfViewer.LoadDocument(stream);
            }
        }
    }
}
