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 User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace PdfViewerSamples
{
    public sealed partial class RenderMode : UserControl
    {
        public RenderMode()
        {
            this.InitializeComponent();
            renderModecb.ItemsSource = Enum.GetValues(typeof(C1.Xaml.PdfViewer.RenderMode));
            this.Loaded += RenderMode_Loaded;
            this.Unloaded += RenderMode_Unloaded;
        }

        void RenderMode_Unloaded(object sender, RoutedEventArgs e)
        {
            c1PdfViewer1.CloseDocument();
        }

        void RenderMode_Loaded(object sender, RoutedEventArgs e)
        {
            Assembly asm = typeof(PdfViewerDemoPage).GetTypeInfo().Assembly;
            Stream stream = asm.GetManifestResourceStream("PdfViewerSamples.Files.C1XapOptimizer.pdf");
            c1PdfViewer1.RenderMode = C1.Xaml.PdfViewer.RenderMode.System;
            c1PdfViewer1.LoadDocument(stream);
            renderModecb.SelectedItem = c1PdfViewer1.RenderMode;
        }

        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();
                c1PdfViewer1.LoadDocument(stream);
            }
        }

        private void renderModecb_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            c1PdfViewer1.RenderMode = (C1.Xaml.PdfViewer.RenderMode)renderModecb.SelectedItem;
        }
    }
}
