Silverlight datagrid列按钮命令(MVVM)

Silverlight datagrid列按钮命令(MVVM),silverlight,mvvm,datagrid,Silverlight,Mvvm,Datagrid,我有以下几点 <ResourceDictionary xmlns:vm="clr-namespace:SilverlightApplication1.ViewModels.Controls"> <DataTemplate DataType="vm:CVItemVM" x:Key="viewmodel"> 参考以下内容(在viewmodel中) 然后你应该对你的虚拟机使用RelativeSource,例如: <Button Content="{Binding

我有以下几点

<ResourceDictionary 

xmlns:vm="clr-namespace:SilverlightApplication1.ViewModels.Controls"> 

<DataTemplate DataType="vm:CVItemVM" x:Key="viewmodel">
参考以下内容(在viewmodel中)

然后你应该对你的虚拟机使用
RelativeSource
,例如:

<Button Content="{Binding Path=Id}" Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" />


where
UserControl
-控件的类型,其中
DataContext
=YourViewModel

是否尝试过相对资源绑定?顺便说一句,你应该写下你真正的问题是什么。在花了将近一天的时间之后,相对资源的建议终于对我起了作用。
<Button Content="{Binding Path=Id}" Command="{Binding Path=DeleteCommand, Mode=TwoWay}" />                                            
ItemsSource="{Binding Path=Publications}"
public ObservableCollection<PublicationVM> Publications
public ICommand DeleteCommand { get; set; }
<Button Content="{Binding Path=Id}" Command="{Binding Path=DeleteCommand, Mode=TwoWay}" />
public ObservableCollection<PublicationVM> Publications
<Button Content="{Binding Path=Id}" Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource AncestorType=UserControl}}" />