我有一个上下文菜单,在右键单击列表视图时会调用它。在做了一些研究之后,我发现这就是你将命令绑定到menuitem的方法。
<ListView.ContextMenu>
<ContextMenu>
<MenuItem Header="Delete">
<MenuItem.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Command" Value="{Binding Path=DataContext.DeleteCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListView}}"/>
</Style>
</MenuItem.ItemContainerStyle>
</MenuItem>
</ContextMenu>
</ListView.ContextMenu>
任何关于命令为什么不被解雇的帮助都会非常感激。感谢。
答案 0 :(得分:1)
<MenuItem Header="Delete" Command="{Binding DeleteCommand}"/>
会为你做的。
当ItemContainerStyle
ItemsSource
为MenuItem
时,会使用 $scope.typeofnotification =[{name:'offer', imges: './resources/remote.png'},
{name:'discount', imges:'./resources/mic.png'},
{name:'upgrades', imges:'./resources/play-icon.png'}];
/*var len = $scope.typeofnotification.length*/
$scope.setNotificationImage = function(){
var notificationImage;
for (var i = 0; i < $scope.typeofnotification.length; i++)
{
if($scope.notificationData[i].notificationType == $scope.typeofnotification[i].name)
{
return notificationImage = $scope.typeofnotification[i].imges;
}
}
};
。