请问如何实现上下文菜单中,使用Command,调用MyViewModel中定义MyDeleteCommand?下面的调用为何没任何反应呢?在Button中直接使用Command设置是成功的,但在MenuItem中总是不成功,请高人指点,多谢。<Window x:Class="MVVM.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MVVM.ViewModels"
Title="Window1" Height="300" Width="300">
<Grid>
<Label Name="label" Content="Test" Margin="5" MinWidth="60">
<Label.ContextMenu>
<ContextMenu Name="contextmenu">
<MenuItem Header="删除序列" Command="{Binding MyViewModel.MyDeleteCommand}" CommandParameter="{Binding ElementName=label,Path=Text}"/>
</ContextMenu>
</Label.ContextMenu> </Label>
</Grid>
</Window>
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:MVVM.ViewModels"
Title="Window1" Height="300" Width="300">
<Grid>
<Label Name="label" Content="Test" Margin="5" MinWidth="60">
<Label.ContextMenu>
<ContextMenu Name="contextmenu">
<MenuItem Header="删除序列" Command="{Binding MyViewModel.MyDeleteCommand}" CommandParameter="{Binding ElementName=label,Path=Text}"/>
</ContextMenu>
</Label.ContextMenu> </Label>
</Grid>
</Window>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货