Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在ListView的ContextMenu中,单击菜单项不会触发预期的命令_C#_Wpf_Listview_Contextmenu_Commandparameter - Fatal编程技术网

C# 在ListView的ContextMenu中,单击菜单项不会触发预期的命令

C# 在ListView的ContextMenu中,单击菜单项不会触发预期的命令,c#,wpf,listview,contextmenu,commandparameter,C#,Wpf,Listview,Contextmenu,Commandparameter,我有一个listview,与每个listviewitem关联的contextmenu。 但是单击菜单项不会调用相应的命令myCommand。 myCommand链接到Execute和Can Execute方法。Can-Execute方法有效,但Execute方法无效。它有一个参数。 如果删除datacontext,则调用Execute方法,但参数始终为null。 我在xaml中的代码: <ListView.ContextMenu> <Contex

我有一个listview,与每个listviewitem关联的contextmenu。 但是单击菜单项不会调用相应的命令myCommand。 myCommand链接到Execute和Can Execute方法。Can-Execute方法有效,但Execute方法无效。它有一个参数。 如果删除datacontext,则调用Execute方法,但参数始终为null。 我在xaml中的代码:

<ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Open Directory " 
                              DataContext="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType=ContextMenu}}"
                              Command="{Binding OpenLink}"
                              CommandParameter="{Binding Path=LocalPath}"/>
                </ContextMenu>
            </ListView.ContextMenu>
简短说明:我的列表中的每个项目都有一个属性LocalPath。当我右键单击一个项目并选择Open Directory时,它应该打开该项目的目录。 谢谢你的帮助

Niko设置DataContext会更改所有绑定的默认绑定上下文。如果要从ListView.SelectedItem获取LocalPath,则只能对该绑定使用RelativeSource绑定,但需要使用PlacementTarget从ContextMenu获取ListView

设置DataContext会更改所有绑定的默认绑定上下文。如果要从ListView.SelectedItem获取LocalPath,则只能对该绑定使用RelativeSource绑定,但需要使用PlacementTarget从ContextMenu获取ListView

设置DataContext会更改所有绑定的默认绑定上下文。如果要从ListView.SelectedItem获取LocalPath,则只能对该绑定使用RelativeSource绑定,但需要使用PlacementTarget从ContextMenu获取ListView

设置DataContext会更改所有绑定的默认绑定上下文。如果要从ListView.SelectedItem获取LocalPath,则只能对该绑定使用RelativeSource绑定,但需要使用PlacementTarget从ContextMenu获取ListView


没问题@Hermios。很高兴它帮了我,没问题@Hermios。很高兴它帮了我,没问题@Hermios。很高兴它帮了我,没问题@Hermios。很高兴这有帮助