1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# Definir el contenido XAML del formulario $XAML = @" <Window x:Class="MiFormulario" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Mi Formulario" Height="200" Width="300"> <Grid> <Label Content="Nombre de usuario:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0"/> <TextBox Name="txtUsuario" HorizontalAlignment="Left" VerticalAlignment="Top" Width="200" Margin="10,30,0,0"/> <Label Content="Contraseña:" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,60,0,0"/> <PasswordBox Name="txtContraseña" HorizontalAlignment="Left" VerticalAlignment="Top" Width="200" Margin="10,80,0,0"/> <Button Content="Iniciar Sesión" Name="btnIniciar" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="30" Margin="10,120,0,0"/> </Grid> </Window> "@ # Cargar la biblioteca de WPF [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework') # Cargar el formulario desde XAML $Formulario = [Windows.Markup.XamlReader]::Load([System.Xml.XmlNodeReader]::new([System.Xml.XmlDocument]::new().CreateElement('root'))) # Definir el evento Click para el botón $Formulario.FindName("btnIniciar").Add_Click({ $usuario = $Formulario.FindName("txtUsuario").Text $contraseña = $Formulario.FindName("txtContraseña").Password Write-Host "Usuario: $usuario" Write-Host "Contraseña: $contraseña" }) # Mostrar el formulario $Formulario.ShowDialog() |