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
Wpf 将父控件列表的项(整个类)传递给命令_Wpf_Mvvm - Fatal编程技术网

Wpf 将父控件列表的项(整个类)传递给命令

Wpf 将父控件列表的项(整个类)传递给命令,wpf,mvvm,Wpf,Mvvm,是否有方法将父集合控件的整个子类(在我的示例中是ListBox)传递到ViewModel中的命令中?我可以传递任何单个值,无论是'IsChecked'、'AttachmentId'还是'Name'。这三个属性都是“附件”类的一部分AttachmentLst'(ListBox的项源包含'Attachment'元素。我想将整个类传递到我的命令中。下面是只传递一个属性的工作代码,在本例中为'AttachmentId'。如何将'Attachment'传递到命令中 使用 CommandParame

是否有方法将父集合控件的整个子类(在我的示例中是ListBox)传递到ViewModel中的命令中?我可以传递任何单个值,无论是'IsChecked'、'AttachmentId'还是'Name'。这三个属性都是“附件”类的一部分AttachmentLst'(ListBox的项源包含'Attachment'元素。我想将整个类传递到我的命令中。下面是只传递一个属性的工作代码,在本例中为'AttachmentId'。如何将'Attachment'传递到命令中


使用

  CommandParameter="{Binding RelativeSource={RelativeSource AncestorType={x:Type StackPanel}},Path=DataContext}"
将整个项目作为
CommandParameter
传递

您还可以使用
templateParent
/
Self
绑定而不是
祖先
Binding.DataContext对所有用户都是相同的