Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ERASE ALL THIS AND PUT XAML BELOW between the @" "@
- $inputXML = @"
- <Window x:Class="UserCreation.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:UserCreation"
- mc:Ignorable="d"
- Title="User Creation Tool" Height="445" Width="320">
- <Grid Margin="0,0,2,0">
- <TextBlock x:Name="textBlockTitle" HorizontalAlignment="Left" Height="20" Margin="10,10,0,0" TextWrapping="Wrap" Text="Use this tool to create new users!" VerticalAlignment="Top" Width="290" FontSize="16" TextAlignment="Center"/>
- <Button x:Name="buttonCreate" Content="Create!" HorizontalAlignment="Left" Height="35" Margin="125,350,0,0" VerticalAlignment="Top" Width="75" FontSize="16"/>
- <TextBox x:Name="textBoxLocationCode" HorizontalAlignment="Left" Height="25" Margin="125,90,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="150"/>
- <TextBox x:Name="textBoxFirstName" HorizontalAlignment="Left" Height="25" Margin="125,135,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="150"/>
- <TextBox x:Name="textBoxLastName" HorizontalAlignment="Left" Height="25" Margin="125,180,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="150"/>
- <TextBox x:Name="textBoxJobTitle" HorizontalAlignment="Left" Height="25" Margin="125,225,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="150"/>
- <TextBlock x:Name="textBlockLocationCode" HorizontalAlignment="Left" Height="25" Margin="25,90,0,0" TextWrapping="Wrap" Text="Location Code:" VerticalAlignment="Top"/>
- <TextBlock x:Name="textBlockFirstName" HorizontalAlignment="Left" Height="25" Margin="25,135,0,0" TextWrapping="Wrap" Text="First Name:" VerticalAlignment="Top"/>
- <TextBlock x:Name="textBlockLastName" HorizontalAlignment="Left" Height="25" Margin="25,180,0,0" TextWrapping="Wrap" Text="Last Name:" VerticalAlignment="Top"/>
- <TextBlock x:Name="textBlockJobTitle" HorizontalAlignment="Left" Height="25" Margin="25,225,0,0" TextWrapping="Wrap" Text="Job Title:" VerticalAlignment="Top"/>
- <Button x:Name="buttonVerify" Content="All Info Correct!" HorizontalAlignment="Left" Margin="112,295,0,0" VerticalAlignment="Top" Width="100" Height="25"/>
- </Grid>
- </Window>
- "@
- $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
- [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
- [xml]$XAML = $inputXML
- #Read XAML
- $reader=(New-Object System.Xml.XmlNodeReader $XAML)
- try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
- catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
- #===========================================================================
- # Load XAML Objects In PowerShell
- #===========================================================================
- $XAML.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
- Function Get-FormVariables{
- if ($global:ReadmeDisplay -ne $true){Write-Host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
- Write-Host "Found the following interactable elements from our form" -ForegroundColor Cyan
- Get-Variable WPF*
- }
- Get-FormVariables
- #===========================================================================
- # Actually make the objects work
- #===========================================================================
- $WPFbuttonVerify.Add_Click(
- {
- If ($WPFbuttonCreate.Visibility -ne 'Visible'){$WPFbuttonCreate.Visibility = 'Visible'}
- Else {$WPFbuttonCreate.Visibility = 'Hidden'}
- }
- )
- $WPFbuttonCreate.Visibility = 'Hidden'
- #Test Variables
- #$LocationCode = "100"
- #$FirstName = "Test"
- #$LastName = "User"
- #$JobTitle = "Manager"
- $WPFbuttonCreate.Add_Click({
- Write-Host $LocationCode
- })
- #Sample entry of how to add data to a field
- #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
- #===========================================================================
- # Shows the form
- #===========================================================================
- Function Show-Form{
- $Form.ShowDialog() | out-null
- }
- Show-Form
- $LocationCode = $WPFtextBoxLocationCode.Text
- $FirstName = $WPFtextBoxFirstName.Text
- $LastName = $WPFtextBoxLastName.Text
- $JobTitle = $WPFtextBoxJobTitle.Text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement