Finding out which treeview node was clicked from context menu.

Sep 20, 2012 at 2:39 AM
Edited Sep 20, 2012 at 2:52 AM

On my treeview, opening up a contextmenu on a treeitem deselects the item. I'd like to find to get the node on where the user has right clicked then selected Open from.

          <TreeView Name="ProgramTree" ItemsSource="{Binding ProgramItemCollection}"

                                    <ContextMenu StaysOpen="True">
                                        <MenuItem Header="Open"
                                        <MenuItem Header="CheckSyntax"/>


        public void ProgramMenuItemOpen(object item)


One solution would be to handle previewmousedown event and programmatically focus the node like shown here but this requires me to break the MVVM pattern.

Any suggestions?