WPF and Powershell - event handling

Can someone point me in the right direction with some documentation on handling WPF interface events in Powershell?

I want to know how, for example, to call a function when changing the CheckBox or Radio button.

Hooray!

Ben

+3
source share
2 answers

Given WPF and PowerShell, take a look at the WPF Linkcollection for PowerShell by Bernd. You will find many interesting links to help you.

Given your problem, just use a template

$control.Add_<someevent>({ what to do })

For example, someeventmaybe Clickfor a button:

$button.Add_Click({ $global:clicked = $true })

You pass in a script block that handles the event.

+5
source

( 4 ). , jpierson .

- , , WPF Googling PowerShell, () Event Args (e), ...

# ( )

private void Handler(object sender, SomeEventArgs e)
{
  //do something with sender and/or e...
}

PowerShell

$WPFControl.Add_Handler({
  $sender = $args[0]
  $e      = $args[1]
  #do something with sender and/or e...
})

MouseWheelHandler

# ( MouseWheelHandler )

private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
  ScrollViewer scv = (ScrollViewer)sender;
  //do something with sender and/or e...
}

PowerShell

$ScrollViewer.Add_PreviewMouseWheel({
  $sender = [System.Windows.Controls.ScrollViewer]$args[0]
  $e      = [System.Windows.Input.MouseWheelEventArgs]$args[1]
  #do something with sender and/or e...
})

PowerShell, ,

$ScrollViewer.Add_PreviewMouseWheel({
  Write-Host $args[0]
  Write-Host $args[1]
})

( ) ...

System.Windows.Controls.ScrollViewer
System.Windows.Input.MouseWheelEventArgs
+6

Source: https://habr.com/ru/post/1758179/


All Articles