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 9165509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:55:39+00:00 2026-06-17T14:55:39+00:00

I am getting the error: System.Windows.Data Error: 4 : Cannot find source for binding

  • 0

I am getting the error:

System.Windows.Data Error: 4 : Cannot find source for binding with
reference ‘ElementName=gridProductViewDataGrid’.
BindingExpression:Path=SelectedItem; DataItem=null; target element is
‘MenuItem’ (Name=”); target property is ‘IsEnabled’ (type ‘Boolean’)

In the Output window of visual studio and my code doesnt do what it is supposed to do.

The add works fine because it is never needing to be disabled but the remove is not being disabled.

<DataGrid AutoGenerateColumns="False" IsReadOnly="False" CanUserAddRows="False" CanUserDeleteRows="False" EnableRowVirtualization="True" ItemsSource="{Binding Items, Mode=TwoWay}" x:Name="gridViewProductDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" >
        <DataGrid.ContextMenu>
            <ContextMenu>
                <MenuItem Header="{Binding LabelStrings.AddProductLabel, Source={StaticResource ResourceWrapper}}" Click="Add_Product_MenuItem_Click"/>
                <MenuItem Header="{Binding LabelStrings.RemoveProductLabel, Source={StaticResource ResourceWrapper}}" Click="Remove_Product_MenuItem_Click" IsEnabled="{Binding ElementName=gridViewProductDataGrid, Path=SelectedItem, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource ObjectToBooleanConverter}}"/>
                </MenuItem>
            </ContextMenu>
        </DataGrid.ContextMenu>

Where the converter simply takes returns true if there is no object and false if it exists.
I have tried moving this code in and out of the grid as well as moving parts of the binding in different orders. When I run the the code and put in a break point, it never went into the code for the boolean converter. Why cant it see the grid when it is inside it?

  • 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-17T14:55:40+00:00Added an answer on June 17, 2026 at 2:55 pm

    A ContextMenu is opened on a different Visual Tree then his parent, and therefore Named Binding won’t work.

    Try something like this:

    IsEnabled="{Binding PlacementTarget.DataContext.SelectedItem, 
                        RelativeSource={RelativeSource FindAncestor,AncestorType=ContextMenu}, 
                        Converter={StaticResource ObjectToBooleanConverter}}"
    

    Which uses the ContextMenu’s PlacementTarget (which is the DataGrid) to get the correct DataContext.

    Another option is to set the NameScope for the ContextMenu. Add the following line to your CodeBehind:

    NameScope.SetNameScope(contextMenu, NameScope.GetNameScope(this));
    

    Where contextMenu is the Name you gave your ContextMenu

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

Sidebar

Related Questions

I'm getting this in my output Window: System.Windows.Data Error: 4 : Cannot find source
I am getting this error: cannot implicitly convert type 'string' to 'System.Data.SqlClient.Sqlconnection' for this
I'm currently getting this error from an InvalidCastException [A]System.Data.Objects.ObjectResult`1[EDMXAssembly.ServiceStatus] cannot be cast to [B]System.Data.Objects.ObjectResult`1[EDMXAssembly.ServiceStatus].
I'm getting a timeout error when trying to execute a LINQ (-to-SQL) query System.Data.SqlClient.SqlException:
at the moment im loading xml and i am getting error: System.Xml.XmlException: ' ',
I keep getting this error System.Web.HttpException was unhandled by user code Message=Validation of viewstate
We are getting this error: System.ServiceModel.ServerTooBusyException: The request to create a reliable session has
I am getting error of System.MissingMethodException after I have an optional parameter in one
I’m getting system error when I try to compile the code below on Visual
I keep getting this error randomly: System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: Server was unable to process request.

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.