Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF将ICommand参数绑定到另一个控件';s SelectedItem_C#_Wpf_Datagrid - Fatal编程技术网

C# WPF将ICommand参数绑定到另一个控件';s SelectedItem

C# WPF将ICommand参数绑定到另一个控件';s SelectedItem,c#,wpf,datagrid,C#,Wpf,Datagrid,我在同一层次结构级别上有一个DataGrid和一个按钮。我需要将数据网格传递给按钮的ICommand参数,然后选择editem属性 这就是我得到的: <DataGrid x:Name="MyListGrid" ItemsSource="{Binding MyList}" Margin="10,10,10,10"> </DataGrid> <Button Content="My Button" Command="{Binding MyCom

我在同一层次结构级别上有一个
DataGrid
和一个
按钮。我需要将
数据网格传递给
按钮的
ICommand
参数,然后选择editem
属性

这就是我得到的:

<DataGrid 
    x:Name="MyListGrid"
    ItemsSource="{Binding MyList}"
    Margin="10,10,10,10">
</DataGrid>

<Button Content="My Button" Command="{Binding MyCommand}" CommandParameter="{Binding Path=SelectedItem, ElementName=MyListGrid}" />

我在
RelayCommand
1上遇到异常。CanExecute(对象参数)
参数为null`。我做错了什么

编辑:可以在此处找到中继命令执行:

您使用的是什么
RelayCommand
实现?如果
参数
为空,它是否会引发异常?因为在这种情况下它应该只返回false。您的CanExecute方法做什么?我使用的是Kinect SDK工具包附带的实现。我已经将它与在某地和其他一些地方发现的流行版本进行了比较,结果完全相同,但有记录在案。我会更新它。在按下“我的按钮”之前,您是否从DataGrid中选择了任何项目?它会在屏幕实际显示之前兑现,因此我无法在未选择任何内容的情况下按下按钮。网格有两行已预加载。