我想在与DataTemplate相关联的上下文菜单中使用CommandParameter属性。CommandParameter应包含对触发数据模板的对象的引用,如下面的代码示例所示。我尝试使用"{Binding Path=this}",但它不起作用,因为"this"不是一个属性。命令会触发,但我无法获得正确的参数。有没有人有关于如何做到这一点的想法?
注意:我通过将其替换为对视图定位器的引用而删除了Command="{Binding DeleteSelectedMeetingCommand}",并且命令正在触发。
注意:我通过将其替换为对视图定位器的引用而删除了Command="{Binding DeleteSelectedMeetingCommand}",并且命令正在触发。
<DataTemplate DataType="{x:Type Models:MeetingDbEntry}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Path=HostTeam}"/>
<TextBlock Grid.Column="1" Text="{Binding Path=GuestTeam}"/>
<TextBlock Grid.Column="2" Text="{Binding Path=Result}"/>
<Grid.ContextMenu>
<ContextMenu Name="MeetingMenu">
<MenuItem Header="Delete"
Command="{Binding
Source={StaticResource Locator},
Path=Main.DeleteSelectedMeetingCommand}"
CommandParameter="{Binding Path=this}"/>
</ContextMenu>
</Grid.ContextMenu>
</Grid>
</DataTemplate>
Thanks,