Skip to content

Commit

Permalink
JM + added Ep ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmoyle committed Jan 31, 2017
1 parent d2b8566 commit 3aec8a7
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions Ep3 CheckBoxesAndRadioButtons/CheckBoxesAndRadioButons.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<#
.NOTES
===========================================================================
Created on: 27/01/2017
Created by: Jim Moyle
GitHub link: https://github.com/JimMoyle/GUIDemo
Twitter: @JimMoyle
===========================================================================
.DESCRIPTION
A description of the file.
#>

function Get-XamlObject {
[CmdletBinding()]
param(
[Parameter(Position = 0,
Mandatory = $true,
ValuefromPipelineByPropertyName = $true,
ValuefromPipeline = $true)]
[Alias("FullName")]
[System.String[]]$Path
)

BEGIN
{
Set-StrictMode -Version Latest
$expandedParams = $null
$PSBoundParameters.GetEnumerator() | ForEach-Object { $expandedParams += ' -' + $_.key + ' '; $expandedParams += $_.value }
Write-Verbose "Starting: $($MyInvocation.MyCommand.Name)$expandedParams"
$output = @{ }
Add-Type -AssemblyName presentationframework, presentationcore
} #BEGIN

PROCESS {
try
{
foreach ($xamlFile in $Path)
{
#Change content of Xaml file to be a set of powershell GUI objects
$inputXML = Get-Content -Path $xamlFile -ErrorAction Stop
[xml]$xaml = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace 'x:Class=".*?"', '' -replace 'd:DesignHeight="\d*?"', '' -replace 'd:DesignWidth="\d*?"', ''
$tempform = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $xaml -ErrorAction Stop))

#Grab named objects from tree and put in a flat structure using Xpath
$namedNodes = $xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]")
$namedNodes | ForEach-Object {
$output.Add($_.Name, $tempform.FindName($_.Name))
} #foreach-object
} #foreach xamlpath
} #try
catch
{
throw $error[0]
} #catch
} #PROCESS

END
{
Write-Output $output
Write-Verbose "Finished: $($MyInvocation.Mycommand)"
} #END
}


$path = 'E:\JimM\Dropbox\Dropbox (Personal)\ScriptScratch\YouTube\Basic Wizard\Basic Wizard'

$wpf = Get-ChildItem -Path $path -Filter *.xaml -file | Where-Object { $_.Name -ne 'App.xaml' } | Get-XamlObject

$wpf.WizardWindowFrame.NavigationService.Navigate($wpf.TitlePage) | Out-Null

$wpf.titleButtonNext.add_Click({
$wpf.WizardWindowFrame.NavigationService.Navigate($wpf.MiddlePage)
})

$wpf.middleButtonNext.add_Click({
$wpf.WizardWindowFrame.NavigationService.Navigate($wpf.FinishPage)
})

$wpf.middleButtonBack.add_Click({
$wpf.WizardWindowFrame.NavigationService.Navigate($wpf.TitlePage)
})

$wpf.FinishButtonBack.add_Click({
$wpf.WizardWindowFrame.NavigationService.Navigate($wpf.MiddlePage)
})

$wpf.WizardWindow.Showdialog() | Out-Null

0 comments on commit 3aec8a7

Please sign in to comment.