在Powershell脚本中向datagrid添加click事件时出错

时间:2019-07-09 18:48:15

标签: wpf powershell xaml datagrid

我正在尝试向现有的Powershell脚本中添加一个Add_CellMouseClick事件。但是,添加代码后,我在Powershell中仍然收到错误消息(请参见下文)。我要添加的代码基于Powershell datagridview cell click event和其他一些似乎无法再次引用的页面。我想我可能缺少一些简单的东西,但找不到可能的东西。

我尝试了代码的一些变体,但仍然遇到相同的错误。不幸的是,我无法找到很多我想做的事的例子。似乎也无法在C#上找到关于此方法的任何Powershell文档。

数据网格的现有xmal代码(与填充数据网格的代码相同)

<DataGrid Name="HistoryGrid" HorizontalAlignment="Left" Height="400" Margin="19,536,-365,0" VerticalAlignment="Top" Width="353">
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding E1}"  Header="Employee #"/>
        <DataGridTextColumn Binding="{Binding E2}"  Header="Employee Name"/>
        <DataGridTextColumn Binding="{Binding E3}"  Header="Employee Username"/>
    </DataGrid.Columns>
</DataGrid>

我尝试了2个选项

$HistoryGrid.Add_CellMouseClick({HistoryClick})

$HistoryGrid.Add_CellMouseClick({if ($_.button -eq 'Left'){HistoryClick}})

我要发生的事情是,当某人单击数据网格中的一项时,它会运行HistoryClick函数。不幸的是,我得到下面的错误。这就是为什么我认为我缺少了一些东西。

  

方法调用失败,因为[System.Windows.Controls.DataGrid]   不包含名为“ Add_CellMouseClick”的方法。在   Utility.ps1:141 char:1   + $ HistoryGrid.Add_CellMouseClick({if($ _。button -eq'Left'){HistoryCl ...   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:InvalidOperation:(:) [],RuntimeException       + FullyQualifiedErrorId:MethodNotFound

0 个答案:

没有答案