Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #create a form (Visual c#/Windows Form/WPF App(.NET Framlework)) in VS Studio Community
- #name the needed widgets (just add Name="widgetName" in the widget beacon
- #copy and paste the xaml file's path in the script bellow
- #finally add the logic before showing the Dialog
- Add-Type -AssemblyName PresentationFramework
- $xamlFile = "C:\Users\¢ombre\source\repos\testWPF01\testWPF01\MainWindow.xaml"
- $inputXML = Get-Content $xamlFile -Raw
- $inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^<Win.*', '<Window'
- [XML]$XAML = $inputXML
- $reader = (New-Object System.Xml.XmlNodeReader $xaml)
- try {
- $window = [Windows.Markup.XamlReader]::Load( $reader )
- } catch {
- Write-Warning $_.Exception
- throw
- }
- $xaml.SelectNodes("//*[@Name]") | ForEach-Object {
- try {
- Set-Variable -Name "var_$($_.Name)" -Value $window.FindName($_.Name) -ErrorAction Stop
- } catch {
- throw
- }
- }
- #Get-Variable var_*
- $var_btn.Add_Click( {
- $var_txtBox.Text = ""})
- $Null = $window.ShowDialog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement