Imports System.IO
Imports DevExpress.Xpf.Bars
Imports DevExpress.Xpf.Core.Native

Public Class VentanaVisorPDF
    ' Private Property DlgGuardar As Guardar
    '  Public st As New MemoryStream
    ' Public Delegate Sub Guardar(PDF As Stream)
    'Public Sub New(pdf As Stream, DelegadoGuardar As Guardar)
    Public Sub New(pdf As Stream)

        ' Llamada necesaria para el diseñador.
        InitializeComponent()
        If pdf IsNot Nothing Then Me.VisorPDF.DocumentSource = pdf
        '    DlgGuardar = DelegadoGuardar

        ' Agregue cualquier inicialización después de la llamada a InitializeComponent().



    End Sub

    '    Private Sub VentanaVisorPDF_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
    'Try
    '    Dim bm As BarManager = TryCast(LayoutHelper.FindElement(VisorPDF, Function(n) TypeOf n Is BarManager), BarManager)
    '    '  If bm Is Nothing Then MsgBox("no funciona")
    '    Dim bbi As New BarButtonItem()
    '    Dim bbil As New BarButtonItemLink()
    '    bbi.Name = "Save"
    '    bbi.Content = "Save"
    '    bbil.BarItemName = "Save"
    '    AddHandler bbi.ItemClick, AddressOf GuardarPDF
    '    bm.Items.Add(bbi)
    '    bm.Bars(0).ItemLinks.Insert(0, bbil)
    'Catch ex As Exception
    '    MsgBox(ex.Message)
    'End Try
    '   End Sub
    Private Sub GuardarPDF(sender As Object, e As ItemClickEventArgs)
        Try
            '    VisorPDF.SaveDocument(st)
            Me.DialogResult = True
            Me.Close()
            'Dim ms As New System.IO.MemoryStream
            'VisorPDF.SaveDocument(ms)
            'DlgGuardar.Invoke(ms)
        Catch ex As Exception
            Me.Close()
            MessageBox.Show(ex.Message, "Error")
        End Try
    End Sub
    Private Sub GuardarPDFComo(sender As Object, e As ItemClickEventArgs)
        Try
            Dim sfd As New Microsoft.Win32.SaveFileDialog
            sfd.FileName = ""
            sfd.Filter = "Archivo pdf|*.pdf"
            sfd.DefaultExt = ".pdf"
            If sfd.ShowDialog() Then              
                VisorPDF.SaveDocument(sfd.FileName)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error")
        End Try
    End Sub

End Class
