Wpf 找不到作为变量的XAML元素-Powershell 2.0

Wpf 找不到作为变量的XAML元素-Powershell 2.0,wpf,xaml,powershell-2.0,Wpf,Xaml,Powershell 2.0,我的脚本在Powershell V2.0 ISE中运行,但不在Powershell脚本中运行。为什么会这样?我知道这里的变量不能为null,但是我从XAML中读取了这些变量,点击按钮就可以了。我得到以下错误: You cannot call a method on a null-valued expression, At C:\Program Files (x86)\Novertz\Main Script\Novertz.ps1 char:7 + $FEL_CP6K01_button.add.c

我的脚本在Powershell V2.0 ISE中运行,但不在Powershell脚本中运行。为什么会这样?我知道这里的变量不能为null,但是我从XAML中读取了这些变量,点击按钮就可以了。我得到以下错误:

You cannot call a method on a null-valued expression,
At C:\Program Files (x86)\Novertz\Main Script\Novertz.ps1 char:7
+ $FEL_CP6K01_button.add.click <<<< <<
     +Category Info           :InvalidOperation
以及powershell脚本:

#Required to load the XAML form and create the PowerShell Variables

cd "C:\Users\Leeds TX 12\Desktop\Novertz\GUI"

./LoadDialog.ps1 -XamlPath 'C:\Users\Leeds TX     12\Desktop\Novertz\GUI\myform.xaml'

$FEL_CP6K01_button.add_Click({#powershell script#})

$xamGUI.ShowDialog() | out-null
XAML:


在单线程单元模式下运行powershell-STA

在单线程单元模式下运行powershell-STA

#Required to load the XAML form and create the PowerShell Variables

cd "C:\Users\Leeds TX 12\Desktop\Novertz\GUI"

./LoadDialog.ps1 -XamlPath 'C:\Users\Leeds TX     12\Desktop\Novertz\GUI\myform.xaml'

$FEL_CP6K01_button.add_Click({#powershell script#})

$xamGUI.ShowDialog() | out-null
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presenta‌​tion" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="No-Vertz"  Height="1080" Width="1920"> 
<Grid Margin="0,0,-233,-101"> <Grid.Effect> <DropShadowEffect/>       </Grid.Effect> 

<Button Name="FEL_CP6K01_button" Content="FEL_CP6K_CH01"  HorizontalAlignment="Left" Margin="23,69,0,0" VerticalAlignment="Top" Width="99"  Height="59"/>