Imports System.Reflection

Class MainWindow
  Public Sub New()
    ' Configuración
    InitializeComponent()
    Try
      ' Restaurar el estado desde los atributos del objeto
      ' de la clase MySettings referenciado por Default
      Dim restoreBounds As Rect = MySettings.Default.MainRestoreBounds
      Left = restoreBounds.Left
      Top = restoreBounds.Top
      Width = restoreBounds.Width
      Height = restoreBounds.Height
      WindowState = MySettings.Default.MainWindowState
    Catch
    End Try
    ' Recursos
    Me.Title = My.Resources.TituloAplicacion
  End Sub

  Private Sub btSaludo_Click(sender As Object, e As RoutedEventArgs)
    ' Atributos globales
    label1.Content = DirectCast(ObtenerInfo(GetType(AssemblyTitleAttribute)), AssemblyTitleAttribute).Title
    label2.Content = DirectCast(ObtenerInfo(GetType(AssemblyDescriptionAttribute)), AssemblyDescriptionAttribute).Description
    label3.Content = DirectCast(ObtenerInfo(GetType(AssemblyCopyrightAttribute)), AssemblyCopyrightAttribute).Copyright
  End Sub

  Private Function ObtenerInfo(atributo As Type, Optional h As Boolean = False) As Object
    ' Atributos globales
    Dim ensamblado As Assembly = Assembly.GetExecutingAssembly()
    Dim atributos As Object() = ensamblado.GetCustomAttributes(atributo, h)
    Return atributos(0)
  End Function

  Private Sub VentanaWPF_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs)
    ' Guardar el estado desde los atributos
    MySettings.Default.MainRestoreBounds = RestoreBounds
    MySettings.Default.MainWindowState = WindowState
    MySettings.Default.Save()
  End Sub
End Class
