Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8175157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:40:18+00:00 2026-06-06T22:40:18+00:00

I’m working on a WPF application and I’m using the MVVM pattern. I use

  • 0

I’m working on a WPF application and I’m using the MVVM pattern. I use MVVMLight to help me handle some Events. I need to forward the “Click” event so that I can pass the arguments as well so that I can know for sure which item that sent the event. If I use the “Command” I cant know for sure that it was the selected item that sent the event – as the item doesnt need to be selected to right click on it.

This is my code for displaying a list of “order lines”. There are two types of order lines, and for one of the data types; “AccessoryOrderLine” – I want to add a context menu.

My problem is that I cannot access my Window’s DataContext. I’ve named the root node in the Window “root”, and I’m trying to access the root’s DataContext, but this failes with the following error:

System.Windows.Data Error: 4 : Cannot find source for binding with
reference ‘ElementName=root’.
BindingExpression:Path=DataContext.PackAccessory; DataItem=null;
target element is ‘EventToCommand’ (HashCode=5903270); target property
is ‘Command’ (type ‘ICommand’)

<ListBox HorizontalContentAlignment="Stretch" Margin="10,0,10,10" DockPanel.Dock="Bottom" Grid.Row="1" ItemsSource="{Binding OrderLines, NotifyOnSourceUpdated=True, NotifyOnTargetUpdated=True, UpdateSourceTrigger=PropertyChanged}">
    <ListBox.Resources>
        <DataTemplate DataType="{x:Type m:UnitOrderLine}">
             <v:OrderLine />
        </DataTemplate>
        <DataTemplate DataType="{x:Type m:AccessoryOrderLine}">
            <v:OrderLine>
                <v:OrderLine.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Pack 1" IsCheckable="False">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <cmd:EventToCommand Command="{Binding ElementName=root, Path=DataContext.PackAccessory }" PassEventArgsToCommand="True" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                         </MenuItem>
                     </ContextMenu>
                 </v:OrderLine.ContextMenu>
             </v:OrderLine>
         </DataTemplate>
     </ListBox.Resources>
 </ListBox>

I’ve also tried to use “TemplatedParent” and then I get access to my “OrderLine” DataContext, but I cant get one step further back to my “MainWindowModel”.

http://www.thomaslevesque.com/2011/03/21/wpf-how-to-bind-to-data-when-the-datacontext-is-not-inherited/

Found a solution to my problem 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:40:20+00:00Added an answer on June 6, 2026 at 10:40 pm

    Found a solution. Updated my original post with the link to my solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.