Imports System.IO
Imports System.Windows.Markup

Class MainWindow

  Private Sub button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles button1.Click
    Using destino As New FileStream("resultado.xaml", FileMode.Create)
      XamlWriter.Save(Me, destino)
      ' Mostrar lo que se ha escrito en el fichero
      Dim resultadoXaml As String = XamlWriter.Save(Me)
      MessageBox.Show(resultadoXaml)
    End Using
  End Sub

  Public Shared Sub Main()
    Dim app As Application = New Application()
    app.Run(New MainWindow())
  End Sub
End Class
