Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports System.Windows.Browser
Imports System.Reflection
Imports C1.Silverlight

Namespace PdfViewerSamples
    Partial Public Class MainPage
        Inherits UserControl
        Public Sub New()
            InitializeComponent()
           
            Dim resource = Application.GetResourceStream(New Uri("/" + New AssemblyName(Assembly.GetExecutingAssembly().FullName).Name + ";component/C1XAPOptimizer.pdf", UriKind.Relative))
            pdfViewer.LoadDocument(resource.Stream)

            AddHandler pdfViewer.RequestNavigate, Sub(s, e)
                                                      If HtmlPage.IsEnabled Then
                                                          Try
                                                              ' HtmlPage.PopupWindow doesn't work for email addresses.
                                                              ' HtmlPage.Window.Navigate seems to work both for webpages and emails.

                                                              HtmlPage.Window.Navigate(e.Uri, "_blank")
                                                          Catch
                                                          End Try
                                                      End If
                                                  End Sub
        End Sub

        Private Sub LoadPdf(ByVal sender As Object, ByVal args As RoutedEventArgs)
            Dim dialog = New OpenFileDialog With {.Filter = "PDF files|*.pdf"}

            If dialog.ShowDialog() = True Then
                Using fileStream = dialog.File.OpenRead()
                    Try
                        pdfViewer.LoadDocument(fileStream)
                    Catch ex As Exception
                        C1MessageBox.Show("Could not load PDF file:" & vbCrLf & ex.Message)
                    End Try
                End Using
            End If
        End Sub
    End Class
End Namespace
