我正在使用MVVM
,Command
当我右键单击我的ListView
. 我做了很多搜索,但我的问题没有解决。
我使用这个 XAML 代码
<ListView ItemsSource="{Binding LibraryList}"
x:Name="MediaList"
Visibility="{Binding MediaListVisibility}"
Margin="149,18,-1,0"
BorderBrush="#FF8BCD7F"
BorderThickness="0"
Background="White">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction Command="{Binding ChooseMediaCommand}"
CommandParameter="{Binding SelectedValue, ElementName=MediaList}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Name}" Header="Name" Width="300" />
<GridViewColumn DisplayMemberBinding="{Binding Time}" Header="Time" Width="70" />
<GridViewColumn DisplayMemberBinding="{Binding Artist}" Header="Artist" Width="120" />
<GridViewColumn DisplayMemberBinding="{Binding Album}" Header="Album" Width="120" />
<GridViewColumn DisplayMemberBinding="{Binding Year}" Header="Year" Width="80" />
</GridView>
</ListView.View>
<ListView.ContextMenu>
<ContextMenu>
<MenuItem Header="Add to playlist" ItemsSource="{Binding PlaylistsList}">
<MenuItem.ItemTemplate>
<DataTemplate>
<MenuItem Header="{Binding Name}"
Command="{Binding AddToPlaylistCommand}"
CommandParameter="{Binding Name}"/>
</DataTemplate>
</MenuItem.ItemTemplate>
</MenuItem>
<MenuItem Header="Remove"/>
</ContextMenu>
</ListView.ContextMenu>
错误信息 :
System.Windows.Data 错误:40:BindingExpression 路径错误:在“对象”“播放列表”(HashCode=16901761)上找不到“AddToPlaylistCommand”属性。BindingExpression:Path=AddToPlaylistCommand; DataItem='播放列表' (HashCode=16901761); 目标元素是'MenuItem'(名称='');目标属性是“命令”(类型“ICommand”)