0

I'm trying to show a ToolTip with the hovered image but with different dimensions.

I tried this:

<Image Source="c:\Pictures\Airplane.jpg" Width="50" Height="50">
    <Image.ToolTip>
        <Image Width="300" Height="300" 
               Source="{Binding Path=Source, RelativeSource={RelativeSource AncestorType=Image, AncestorLevel=1}}
    </Image.ToolTip>
</Image>

The above makes a bigger image on hover but the image content is blank, probably the binding didn't work.

After hours I think I need help... what am I missing?

I don't want other solutions to the problem like this answer as I'm only trying to practice my binding skills, thanks.

Community
  • 1
  • 1
gdoron
  • 147,333
  • 58
  • 291
  • 367
  • So what's the `BindingExpression` error in your debug window? – DHN Mar 18 '13 at 11:57
  • @DHN, never heard on such a thing, how can I see it? – gdoron Mar 18 '13 at 12:04
  • Well if you have a look in your debug output window of your Visual Studio (VS > Debug > Windows > Output) you can see a lots of output. The `BindingExpression` error will also appear there. It's not much, but you will get an idea what may be wrong. – DHN Mar 18 '13 at 12:07
  • @DHN, _"Could not find source..."_ not much indeed. thanks anyway. – gdoron Mar 18 '13 at 12:10
  • One thing also for tracking binding errors is: You can supply a Flag to your bindings to make the debug output more informative. '{Binding Path=Something, PresentationTraceSources.TraceLevel=High}' – dowhilefor Mar 18 '13 at 12:50

1 Answers1

3

Ok i got it to work, my initial thought was correct: RelativeSource won't work because the tooltip is not part of the visual tree. I thought ElementName would work, but it seems WPF creates a new name namescope of some sort (not sure). So the only way to get it to work, was to use the DataContext as "proxy" between the two visual trees. You could also use a viewmodel with the proper informations.

<Image x:Name="myImage" Source="c:\Pictures\Airplane.jpg" DataContext="{Binding RelativeSource={RelativeSource Self}}" Width="50" Height="50">
    <Image.ToolTip>
        <Image Width="300" Height="300" Source="{Binding Path=Source}"/>
    </Image.ToolTip>
</Image>

enter image description here

dowhilefor
  • 10,971
  • 3
  • 28
  • 45
  • Didn't help, and telling the truth, I can't understand why it should have. – gdoron Mar 18 '13 at 12:07
  • Ok, then try something completely different. I think it won't work because RelativeSource can't find the Image, because its not a logical parent. I update my answer and see if that works. – dowhilefor Mar 18 '13 at 12:14
  • Actually no, i was sure it worked because we did something similar. I'm testing it right now because now i'm hooked :) – dowhilefor Mar 18 '13 at 12:38
  • @makc sorry that was my fault. He commented on my answer when it was wrong. I completely changed it, which unfortunately makes the comments out of context. :/ – dowhilefor Mar 18 '13 at 13:19
  • @Makc & dowhilefor. Let's delete our comments. – gdoron Mar 18 '13 at 14:55
  • Thanks, that datacontext as a proxy is the most "hacky" thing I saw, but it's cool... :) thanks. – gdoron Mar 18 '13 at 14:56