### Install XAMLgui Module
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Installs the XAMLgui module from the PowerShell gallery. Ensure you have an active internet connection.
```powershell
Install-Module -name XAMLgui
```
--------------------------------
### Start Await Job with InitBlock
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Initiates a job that can be awaited, with support for an initialization block. The InitBlock can be constructed using Get-FnAsString.
```powershell
Start-AwaitJob -InitBlock (@( Get-FnAsString "fn1", Get-FnAsString "fn2" ) -Join "`n")
```
--------------------------------
### Download XAMLgui Module Locally
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Saves the XAMLgui module to the current directory without installing it globally. This creates a subfolder for the module.
```powershell
Save-Module -Name XAMLgui -Path .\
```
--------------------------------
### Add Type Assembly
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Example of adding types from System.Drawing and System.Windows.Forms assemblies, as mentioned in v1.1.5.
```powershell
Add-Type -AssemblyName System.Drawing,System.Windows.Forms
```
--------------------------------
### Module Management Functions
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Functions for finding, getting, and importing local modules.
```APIDOC
## Find-LocalModulePath
### Description
Find the path of a module in the current directory.
### Method
Cmdlet
### Endpoint
N/A
### Parameters
#### Path Parameters
- **Name** (string) - Required - The name of the module.
- **Path** (String) - Optional - The base path to search in. Defaults to ".\ps-modules".
### Request Example
```powershell
Find-LocalModulePath -Name "MyModule"
```
### Response
- **string** - The path to the module if found.
```
```APIDOC
## Get-LocalModule
### Description
Get the path of a module in the current directory if it exists, otherwise download it and return its path.
### Method
Cmdlet
### Endpoint
N/A
### Parameters
#### Path Parameters
- **Name** (string) - Required - The name of the module.
- **Path** (String) - Optional - The base path to search in. Defaults to ".\ps-modules".
- **Download** (Boolean) - Optional - Whether to download the module if not found. Defaults to $True.
### Request Example
```powershell
Get-LocalModule -Name "MyModule" -Download $true
```
### Response
- **string** - The path to the module.
```
```APIDOC
## Import-LocalModule
### Description
Import a module from the current directory's `\ps-module` folder.
### Method
Cmdlet
### Endpoint
N/A
### Parameters
#### Path Parameters
- **Name** (string) - Required - The name of the module.
- **Path** (String) - Optional - The base path to search in. Defaults to ".\ps-modules".
- **Download** (Boolean) - Optional - Whether to download the module if not found. Defaults to $True.
### Request Example
```powershell
Import-LocalModule -Name "MyModule"
```
### Response
None
```
```APIDOC
## Set-LocalModulePathBase
### Description
Use to set the a default path for LocalModule commands.
### Method
Cmdlet
### Endpoint
N/A
### Parameters
#### Path Parameters
- **Path** (string) - Required - The base path for local modules.
### Request Example
```powershell
Set-LocalModulePathBase -Path "C:\Modules"
```
### Response
None
```
--------------------------------
### Start Await Job Arguments Type
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Ensures the -Arguments parameter for Start-AwaitJob is of the correct Object[] type. This was a fix in v1.1.4.
```powershell
Start-AwaitJob -Arguments
```
--------------------------------
### Start and Wait for AwaitJob
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Runs long-running operations in background jobs, keeping the UI responsive. Supports synchronous blocking and asynchronous execution with optional initialization blocks and working directories. Requires XAMLgui module import.
```powershell
Import-Module -Name XAMLgui
# Synchronous background job (blocks but keeps UI responsive)
$result = Start-AwaitJob -ScriptBlock {
param($url)
Invoke-WebRequest -Uri $url -UseBasicParsing
return "Download complete"
} -ArgumentList @("https://example.com/data.json")
Write-Host $result
```
```powershell
# Asynchronous background job
$job = Start-AwaitJob -ScriptBlock {
Start-Sleep -Seconds 5
return "Long operation finished"
} -Await $False
# Do other work while job runs...
Write-Host "Job started, continuing with other work..."
# Wait for completion when ready
$result = Wait-AwaitJob $job
Write-Host $result
```
```powershell
# Job with working directory and initialization block
$result = Start-AwaitJob -ScriptBlock {
Get-ChildItem | Select-Object Name
} -Dir "C:\Projects" -InitBlock "Import-Module MyModule"
```
--------------------------------
### Get File Icon
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Retrieves an icon from a file, suitable for window icons or notification bubbles.
```powershell
Get-IconFromFile
```
--------------------------------
### Get XAMLgui Version
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Retrieves the version of the XAMLgui module. Useful when files are loaded directly without importing the module.
```powershell
Get-XAMLguiVersion
```
--------------------------------
### Get Function as String
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Useful for dynamically generating script blocks, particularly for functions like Start-AwaitJob. Ensure functions are defined before calling this.
```powershell
Get-FnAsString
```
--------------------------------
### Get Local Module
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Downloads a module if it's not present and returns its path. In v1.1.4, it was updated to use the '\ps-modules' subfolder.
```powershell
Get-LocalModule
```
--------------------------------
### Get Known Events
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Lists events that are recognized by XAMLgui. In v1.1.7, more events were added, and Add-KnownEventsByControlName was introduced.
```powershell
Get-KnownEvents
```
--------------------------------
### Get PowerShell Interpreter Path
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Retrieves the current PowerShell executable path and checks for the availability of 'powershell.exe' or 'pwsh.exe'.
```powershell
Get-PowershellInterpreter
```
--------------------------------
### Initialize and Display Window
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Loads a XAML file to generate UI elements and the window object, then displays the window.
```PowerShell
$Elements, $Window = . New-Window ".\MainWindow.xaml" -Debug
# Show main window
$Window | Show-Window
```
--------------------------------
### Initialize Application Workflow
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Sets up the application environment by hiding the console and enabling visual styles.
```powershell
Import-Module -Name XAMLgui
# Hide console for clean GUI experience
Hide-Console | Out-Null
Enable-VisualStyles
```
--------------------------------
### Set-RunOnce
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Configures a script to run automatically at next Windows startup using the RunOnce registry key.
```APIDOC
## Set-RunOnce
### Description
Configures a script to run automatically at next Windows startup using the RunOnce registry key.
### Method
POST
### Endpoint
N/A (Function within a module)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **KeyName** (string) - Required - A unique name for the RunOnce entry.
- **Command** (string) - Optional - The command to execute. Defaults to the current script.
- **Params** (string) - Optional - Parameters to pass to the command.
- **Interpreter** (string) - Optional - The path to the interpreter (e.g., PowerShell.exe).
### Request Example
```powershell
# Run current script at next startup
Set-RunOnce -KeyName "MyAppSetup"
# Run a specific script with custom command
Set-RunOnce -KeyName "ConfigureSystem" `
-Command "-executionpolicy bypass -file `"C:\Setup\configure.ps1`"" `
-Params "-Silent"
# Specify PowerShell interpreter explicitly
Set-RunOnce -KeyName "UpdateCheck" `
-Command "-file `"C:\MyApp\update.ps1`"" `
-Interpreter "C:\Program Files\PowerShell\7\pwsh.exe"
```
### Response
#### Success Response (200)
- **Status** (string) - Indicates success or failure of setting the RunOnce key.
#### Response Example
```json
{
"Status": "Success"
}
```
```
--------------------------------
### Get Write Error Clean Mode
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Retrieves the current mode for Write-ErrorClean. This function was added in v1.1.6.
```powershell
Get-WriteErrorCleanMode
```
--------------------------------
### Configure RunOnce Registry Keys
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Schedules scripts to run at the next Windows startup.
```powershell
Import-Module -Name XAMLgui
# Run current script at next startup
Set-RunOnce -KeyName "MyAppSetup"
# Run a specific script with custom command
Set-RunOnce -KeyName "ConfigureSystem" `
-Command "-executionpolicy bypass -file `"C:\Setup\configure.ps1`"" `
-Params "-Silent"
# Specify PowerShell interpreter explicitly
Set-RunOnce -KeyName "UpdateCheck" `
-Command "-file `"C:\MyApp\update.ps1`"" `
-Interpreter "C:\Program Files\PowerShell\7\pwsh.exe"
# Get current interpreter info
$current, $available = Get-PowershellInterpreter
Write-Host "Current: $current"
Write-Host "Available: $($available | ConvertTo-Json)"
```
--------------------------------
### Create a window from a XAML file
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Loads a WPF window from a local file and binds event handlers using the naming convention WindowClass.ElementEventName.
```powershell
Import-Module -Name XAMLgui
# Define event handler using naming convention: WindowClass.ElementEventName
function ProjectTest1.MainWindow.btnSubmit_Click($Sender, $EventArgs) {
Show-MessageBox "Button was clicked!"
}
# Load window from XAML file (dot-source to enable handler binding)
$Elements, $MainWindow = . New-Window ".\MainWindow.xaml" -Debug
# Access named elements directly
$Elements.txtUsername.Text = "DefaultUser"
$Elements.lvItems.ItemsSource = @("Item1", "Item2", "Item3")
# Display the window as a modal dialog
$MainWindow | Show-Window
```
--------------------------------
### Create a window from a XAML string
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Initializes a window directly from a XAML string, useful for dynamic UI generation.
```powershell
Import-Module -Name XAMLgui
$xamlContent = @"
"@
$Elements, $Window = New-WindowXamlString $xamlContent
$Elements.btnOK.Add_Click({
$script:UserName = $Elements.txtName.Text
$Window.Close()
})
$Window | Show-Window
Write-Host "User entered: $UserName"
```
--------------------------------
### Window Creation and Display Functions
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Functions for creating and showing windows from XAML, URLs, or XAML strings.
```APIDOC
## New-Window
### Description
Create a new window from a XAML file.
### Method
Cmdlet
### Endpoint
N/A
### Parameters
#### Path Parameters
- **XamlPath** (string) - Required - The path to the XAML file.
- **Debug** (bool) - Optional - Enable debug mode.
### Request Example
```powershell
New-Window -XamlPath "C:\MyWindow.xaml" -Debug $true
```
### Response
- **object** - The created window object.
```
```APIDOC
## New-WindowUrl
### Description
Create a new window from a URL.
### Method
Cmdlet
### Endpoint
N/A
### Parameters
#### Path Parameters
- **Url** (string) - Required - The URL to load.
- **Debug** (bool) - Optional - Enable debug mode.
### Request Example
```powershell
New-WindowUrl -Url "http://example.com/window.xaml" -Debug $true
```
### Response
- **object** - The created window object.
```
```APIDOC
## New-WindowXamlString
### Description
Create a new window from a XAML string.
### Method
Cmdlet
### Endpoint
N/A
### Parameters
#### Path Parameters
- **XamlString** (string) - Required - The XAML content as a string.
- **Debug** (bool) - Optional - Enable debug mode.
### Request Example
```powershell
New-WindowXamlString -XamlString "Hello" -Debug $true
```
### Response
- **object** - The created window object.
```
```APIDOC
## Show-Window
### Description
Show the window with the dialog window style.
### Method
Cmdlet
### Endpoint
N/A
### Parameters
#### Path Parameters
- **window** ([$Elements)|$(Window]) - Required - The window object to show.
- **dialog** (bool) - Optional - Whether to show as a dialog window. Defaults to $true.
### Request Example
```powershell
$myWindow = New-Window -XamlPath "MyWindow.xaml"
Show-Window -window $myWindow -dialog $false
```
### Response
None
```
--------------------------------
### New-Window
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Creates a new WPF window from a XAML file and returns an elements hashtable with all named UI elements and the window object. Automatically parses the XAML, binds event handlers based on function naming conventions, and prepares the window for display.
```APIDOC
## New-Window
### Description
Creates a new WPF window from a XAML file and returns an elements hashtable with all named UI elements and the window object. Automatically parses the XAML, binds event handlers based on function naming conventions, and prepares the window for display.
### Method
`New-Window`
### Parameters
#### Path Parameters
- **Path** (string) - Required - The path to the XAML file.
- **Debug** (switch) - Optional - Enables debug output during window creation.
#### Request Body
None
### Request Example
```powershell
Import-Module -Name XAMLgui
# Define event handler using naming convention: WindowClass.ElementEventName
function ProjectTest1.MainWindow.btnSubmit_Click($Sender, $EventArgs) {
Show-MessageBox "Button was clicked!"
}
# Load window from XAML file (dot-source to enable handler binding)
$Elements, $MainWindow = . New-Window ".\MainWindow.xaml" -Debug
# Access named elements directly
$Elements.txtUsername.Text = "DefaultUser"
$Elements.lvItems.ItemsSource = @("Item1", "Item2", "Item3")
# Display the window as a modal dialog
$MainWindow | Show-Window
```
### Response
#### Success Response (200)
- **Elements** (hashtable) - A hashtable containing all named UI elements from the XAML.
- **MainWindow** (System.Windows.Window) - The main window object.
#### Response Example
```powershell
# Example response structure (actual content depends on XAML)
$Elements = @{
txtUsername = [System.Windows.Controls.TextBox]
lvItems = [System.Windows.Controls.ListView]
btnSubmit = [System.Windows.Controls.Button]
}
$MainWindow = [System.Windows.Window]
```
```
--------------------------------
### Basic XAMLgui Usage with Event Handler
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Imports the XAMLgui module, hides the console, defines a simple event handler for a button click, and then displays a XAML window. The event handler must match the window class name and element's event name.
```powershell
Import-Module -Name XAMLgui
Hide-Console | Out-Null
Function ProjectTest1.MainWindow.btnHelloWorld_Click {
Show-MessageBox "Hello World!"
}
. New-Window .\MainWindow.xaml -Debug | Show-Window
```
--------------------------------
### Configure Known Events and Window Loading
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Sets the list of events to track and initializes a window from a XAML file.
```powershell
Set-KnownEvents @(
"Click", "MouseDown", "MouseUp",
"KeyDown", "KeyUp", "TextChanged",
"SelectionChanged", "Loaded", "Closing"
)
# Now load window with custom event detection
$Elements, $Window = . New-Window ".\MainWindow.xaml" -Debug
```
--------------------------------
### Version Information
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Function to retrieve the XAMLgui version.
```APIDOC
## Get-XAMLguiVersion
### Description
Returns the current XAMLgui version (because: loading the files directly without importing, would not provide the version).
### Method
Cmdlet
### Endpoint
N/A
### Parameters
None
### Request Example
```powershell
Get-XAMLguiVersion
```
### Response
- **string** - The current XAMLgui version.
```
--------------------------------
### Select Folder Dialog
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Opens a folder browser dialog for single or multiple folder selection. Supports custom titles, descriptions, initial paths, and new folder creation. Requires XAMLgui module import.
```powershell
Import-Module -Name XAMLgui
# Simple folder selection
$folder = Select-FolderDialog -Title "Select Output Folder"
```
```powershell
if ($folder) {
Write-Host "Selected folder: $folder"
}
```
```powershell
# Advanced folder dialog with options
$folders = Select-FolderDialog -Title "Select Backup Locations" `
-Description "Choose folders to include in backup" `
-Path "C:\Users" `
-Multiselect $true `
-ShowNewFolderButton $true
```
```powershell
foreach ($folder in $folders) {
Write-Host "Will backup: $folder"
}
```
--------------------------------
### Select File Dialog
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Opens a file browser dialog for selecting one or multiple files. Allows filtering by extension and setting an initial path. Requires XAMLgui module import.
```powershell
Import-Module -Name XAMLgui
# Select image files
$files = Select-FileDialog -Title "Select Images" `
-Filter "Images (*.jpg, *.png)|*.jpg;*.png" `
-Multiselect $true
```
```powershell
foreach ($file in $files) {
Write-Host "Selected: $file"
}
```
```powershell
# Select configuration file
$configFile = Select-FileDialog -Title "Select Configuration" `
-Path "C:\MyApp\Config" `
-Filter "Config Files (*.ini, *.xml)|*.ini;*.xml|All Files (*.*)|*.*"
```
```powershell
if ($configFile) {
$config = Get-Content $configFile
}
```
```powershell
# Select PowerShell scripts
$scripts = Select-FileDialog -Title "Select Scripts to Run" `
-Filter "PowerShell (*.ps1)|*.ps1" `
-Multiselect $true
```
--------------------------------
### Set Run Once Script Execution
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Configures a script to run once at startup. In v1.1.7, it defaults to the currently used PowerShell version with a full path. In v1.1.3, an -Interpreter parameter was added.
```powershell
Set-RunOnce
```
--------------------------------
### Show-Window
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Displays a window either as a modal dialog (blocking) or non-modal window (non-blocking). Accepts both window objects and element hashtables.
```APIDOC
## Show-Window
### Description
Displays a window either as a modal dialog (blocking) or non-modal window (non-blocking). Accepts both window objects and element hashtables.
### Method
`Show-Window`
### Parameters
#### Path Parameters
None
#### Query Parameters
- **dialog** (boolean) - Optional - If `$True` (default), shows the window as a modal dialog. If `$False`, shows it as a non-modal window.
#### Request Body
None
### Request Example
```powershell
Import-Module -Name XAMLgui
$Elements, $MainWindow = . New-Window ".\MainWindow.xaml"
# Show as modal dialog (default) - blocks until window is closed
$MainWindow | Show-Window
# Show as non-modal window - continues script execution
$MainWindow | Show-Window -dialog $False
# Can also pass the elements hashtable directly
$Elements | Show-Window -dialog $False
```
### Response
None (This function displays a window and does not return a value directly related to the display operation itself.)
```
--------------------------------
### Import Local Module
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
Loads a module from the '.\ps_modules' directory, with the capability to download and import it if necessary. Added in v1.1.3.
```powershell
Import-LocalModule
```
--------------------------------
### Load a window from a remote URL
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Fetches a XAML definition from a remote URL to enable centralized UI management.
```powershell
Import-Module -Name XAMLgui
# Load XAML from a remote URL
$Elements, $Window = New-WindowUrl "https://example.com/ui/MainWindow.xaml" -Debug
# Attach handlers after loading
$Elements.btnRefresh.Add_Click({
Write-Host "Refreshing data..."
})
$Window | Show-Window
```
--------------------------------
### Start-AwaitJob and Wait-AwaitJob
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Runs long-running operations in background jobs while keeping the UI responsive, with optional async execution.
```APIDOC
## Start-AwaitJob and Wait-AwaitJob
### Description
Runs long-running operations in background jobs while keeping the UI responsive, with optional async execution.
### Method
Cmdlet
### Endpoint
N/A (Local cmdlets)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```powershell
# Synchronous background job (blocks but keeps UI responsive)
$result = Start-AwaitJob -ScriptBlock {
param($url)
Invoke-WebRequest -Uri $url -UseBasicParsing
return "Download complete"
} -ArgumentList @("https://example.com/data.json")
Write-Host $result
# Asynchronous background job
$job = Start-AwaitJob -ScriptBlock {
Start-Sleep -Seconds 5
return "Long operation finished"
} -Await $False
# Do other work while job runs...
Write-Host "Job started, continuing with other work..."
# Wait for completion when ready
$result = Wait-AwaitJob $job
Write-Host $result
# Job with working directory and initialization block
$result = Start-AwaitJob -ScriptBlock {
Get-ChildItem | Select-Object Name
} -Dir "C:\Projects" -InitBlock "Import-Module MyModule"
```
### Response
#### Success Response (200)
- **$result** (string or object) - The result of the background job's script block execution.
- **$job** (object) - A job object representing the background task.
#### Response Example
```powershell
# Example for synchronous job result
"Download complete"
# Example for asynchronous job result after waiting
"Long operation finished"
# Example for job with working directory
[
{ "Name": "file1.txt" },
{ "Name": "script.ps1" }
]
```
```
--------------------------------
### New-WindowXamlString
Source: https://context7.com/bananaacid/xamlgui/llms.txt
Creates a window directly from a XAML string instead of a file, useful for dynamically generated interfaces or embedded UI definitions.
```APIDOC
## New-WindowXamlString
### Description
Creates a window directly from a XAML string instead of a file, useful for dynamically generated interfaces or embedded UI definitions.
### Method
`New-WindowXamlString`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **XamlString** (string) - Required - The XAML content as a string.
### Request Example
```powershell
Import-Module -Name XAMLgui
$xamlContent = @"
"@
$Elements, $Window = New-WindowXamlString $xamlContent
$Elements.btnOK.Add_Click({
$script:UserName = $Elements.txtName.Text
$Window.Close()
})
$Window | Show-Window
Write-Host "User entered: $UserName"
```
### Response
#### Success Response (200)
- **Elements** (hashtable) - A hashtable containing all named UI elements from the XAML.
- **Window** (System.Windows.Window) - The main window object.
#### Response Example
```powershell
# Example response structure (actual content depends on XAML)
$Elements = @{
txtName = [System.Windows.Controls.TextBox]
btnOK = [System.Windows.Controls.Button]
}
$Window = [System.Windows.Window]
```
```
--------------------------------
### Handle Window Class Optional
Source: https://github.com/bananaacid/xamlgui/blob/main/README.md
The 'class' attribute in '