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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:55:35+00:00 2026-05-16T16:55:35+00:00

What am I doing wrong here?: <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <Button> <Button.ToolTip> <TextBlock Text={Binding Path=Title,

  • 0

What am I doing wrong here?:

 <GridViewColumn>
    <GridViewColumn.CellTemplate>
       <DataTemplate>
          <Button>
            <Button.ToolTip>
              <TextBlock Text="{Binding Path=Title, RelativeSource={RelativeSource AncestorType=Window}}" />

That’s just a simplified example, that doesn’t work anyway 🙂
Actually I need to get a value from another property that is in scope of the Window’s DataContext.

Help me pls.

  • 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-05-16T16:55:36+00:00Added an answer on May 16, 2026 at 4:55 pm

    This is tricky because ToolTip is not part of the VisualTree. Here you see a cool solution for the same problem with ContextMenus. The same way you can go for the ToolTip.

    UPDATE
    Sadly the link is gone and I have not found the referenced article anymore.
    As far as I remember, the referenced blog has shown how to bind to a DataContext of another VisualTree, which is often necessay when binding from a ToolTip, a ContextMenu or a Popup.

    A nice way to do this, is to provide the desired instance (e.g. ViewModel) within the Tag-property of the PlacementTarget. The following example does this for accessing a Command-instance of a ViewModel:

    <Button Tag="{Binding DataContext,RelativeSource={RelativeSource Mode=Self}}">
      <Button.ContextMenu>
        <ContextMenu>
           <MenuItem Command="{Binding PlacementTarget.Tag.DesiredCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}}" .../>
        <ContextMenu>
      </Button.ContextMenu>
    </Button>
    

    I have not tested it and its a long time I did this the last time. Please make a comment if it does not work for you.

    UPDATE 2

    As the original link that this answer was written about is gone, I hit archive.org and found the original blog entry. Here it is, verbatim from the blog:

    Because a ContextMenu in WPF does not exist within the visual tree of
    your page/window/control per se, data binding can be a little tricky.
    I have searched high and low across the web for this, and the most
    common answer seems to be “just do it in the code behind”. WRONG! I
    didn’t come in to the wonderful world of XAML to be going back to
    doing things in the code behind.

    Here is my example to that will allow you to bind to a string that
    exists as a property of your window.

    public partial class Window1 : Window
    {
        public Window1()
        {
            MyString = "Here is my string";
        }
    
        public string MyString
        {
            get;
            set;
    
        }
    }
    
    
    <Button Content="Test Button" 
         Tag="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}}">
      <Button.ContextMenu>
        <ContextMenu DataContext="{Binding Path=PlacementTarget.Tag, 
              RelativeSource={RelativeSource Self}}" >
          <MenuItem Header="{Binding MyString}"/>
        </ContextMenu>
      </Button.ContextMenu>   
    </Button>
    

    The important part is the Tag on the button(although you could just as
    easily set the DataContext of the button). This stores a reference to
    the parent window. The ContextMenu is capable of accessing this
    through it’s PlacementTarget property. You can then pass this context
    down through your menu items.

    I’ll admit this is not the most elegant solution in the world.
    However, it beats setting stuff in the code behind. If anyone has an
    even better way to do this I’d love to hear it.

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

Sidebar

Related Questions

What am I doing wrong here? <!doctype html> <html> <head> <title>Testing</title> <script src=mustache.js></script> </head>
what am I doing wrong here? I'm trying to create a DataTemplate using a
What am I doing wrong here folks? <?php include 'header.php'; /** * Display a
What am I doing wrong here? I'm trying to get started with jQuery UI
What am I doing wrong here: class Helo { // main: generate some simple
What am I doing wrong here? I'm serializing a value, storing it in a
What am I doing wrong here? private void SendMail(string from, string body) { string
What am I doing wrong here? Im trying to save a canvas drawing by
What am I doing wrong here? It says Database Count Failed (on the $count
What am I doing wrong here? Declare @starttimestamp datetime = getdate(); RAISERROR(N'Code not valid

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.