How to call a method of a WPF form element launched in another workspace in Powershell

I play using spaces in PowerShell to improve the performance of a small GUI application.

What I still have is a space that has two goals: firstly, it contains all my other spaces, and secondly, it parses my xml XML file and displays it. It also adds nodes to the synchronized hash table, so I have access to it in all spaces. As you can imagine, I have a few buttons in this GUI that trigger actions when clicked; pretty simple stuff and actually it still works great. I can exchange data between workspaces, and I can also update the GUI by clicking on a specific button.

However, I cannot call the addChild () method on an empty stack in my XML file. What I basically want to do is just add checkboxes on the stack (named "CheckboxViewer").

$checkbox = New-Object System.Windows.Controls.CheckBox
$checkbox.Content = "Hello world"
$syncHash.checkbox = $checkbox
$syncHash.CheckboxViewer.Dispatcher.Invoke(
     [Action]{
         #this is working:
         $syncHash.CheckboxViewer.Background = 'Black'
         #this is not working
         $syncHash.CheckboxViewer.AddChild($syncHash.checkbox)
     }, "Normal")

, , , ( ):

Exception "AddChild" "1": " , .

, ? , !

+4
1

:

$syncHash.Window.Dispatcher.Invoke([action]{
    $checkbox = New-Object System.Windows.Controls.CheckBox
    $checkbox.Content = "Hello world"
    $syncHash.CheckboxViewer.AddChild($checkbox)
}, "Normal")

, [action]

+1

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


All Articles