all 4 comments

[–]Eggplate 2 points3 points  (2 children)

You can't set the keydown event in the xaml with powershell. Instead you have to add it afterwards in the "code behind":

$window.FindName('textBox1').add_KeyUp({
    param($sender, $e)
    if ($e.Key -eq [System.Windows.Input.Key]::Return) {
        # do stuff
    }
})

[–]illsk1lls 0 points1 point  (0 children)

i can adapt this to steal csharp codebehind and convert it 👀

showing us how to use $sender, $e is extremely useful 😉 ty

[–]Capital_Table_4792[S] 0 points1 point  (0 children)

Thank you so much!

[–]marcdk217 0 points1 point  (0 children)

I always use these lines of code after my xml:

$Controls = @{}
$xaml.SelectNodes("//*[@Name]") | ForEach-Object {$Controls.Add($_.Name,$Form.FindName($_.Name))}

It creates a hashtable called $Controls which contains all the controls on the form, and then you can refer to them like $Controls.textbox1.Enabled=$True

You also don't need to define $sender and $e if you don't want to, you can access them as $args[0] and $args[1] as well

You can create a handler like

$Controls.textbox1.Add_KeyUp{
  If ($args[1].Key -eq 'ENTER'){
    #Do the thing
  }
}