See Karl Shifflett for the full explanation of how to inherit the DataContext of the 'owning' control from the ToolTip: karlshifflett.wordpress.com/2007/12/29/w....
Up vote 1 down vote favorite share g+ share fb share tw.
I have a style that I am using to make dynamic tooltips on certain text boxes like so. This works very well, but if I want to use a more complex tooltip I can't figure out how to bind to 'Tag' anymore for the converter value. For example; ... ... I have tried several flavors of 'FindAncestor' and what not for the relative source, but I can't get anything to work.
Any ideas? UPDATE: 12-29-2010 : Here is the correct code, answer provided by our friend Goblin below. Works perfectly!
... ... wpf binding styles link|improve this question edited Aug 16 '11 at 15:59Dave Clemmer1,78331030 asked Dec 2 '10 at 15:37A.R.2,306314 78% accept rate.
UPDATE: It seems that the converter is not being called in this arrangement no matter what I set the value binding to. However, there are no exceptions being reported by the application when it is running. This only adds to the mystery.
– A.R. Dec 2 '10 at 16:21 Not really - it's because the DataContext of the TextBlock is null - hence the Binding is 'sleeping' until a DataContext is set. – Goblin Dec 2 '10 at 19:06.
See Karl Shifflett for the full explanation of how to inherit the DataContext of the 'owning' control from the ToolTip: karlshifflett.wordpress.com/2007/12/29/w... It isn't exactly Textbook stuff :).
Sorry for the long long delay in trying this out. The project got bumped to the bottom of my list after all. Anyway, after reading through the article, this is exactly what I was looking for.
I updated my questions with the working code. Thanks! – A.R. Dec 29 '10 at 15:51 No worries - glad I could help :-) – Goblin Dec 29 '10 at 21:18.
The problem is that ToolTips are popups that exist outside of the main visual tree, which causes both RelativeSource and ElementName to break when looking for elements outside the ToolTip. The easiest way around this is to use the inherited DataContext for your Bindings as that is passed through to the ToolTip, but this doesn't always give access to what you need. An alternative is to use a custom Attached Property declared with FrameworkMetadataOptions.Inherits.
You can then set a value for that property on the owner object (TextBox in this case) and then access the inherited value on any element inside the ToolTip. In this case you would set the Attached Property value instead of the Tag.
I understand about the tooltip existing outside of main visual tree etc., but the first block of XAML actually works so it seems that there is a way to get at the tag property within the tooltip itself. Why is it accessible in the first case, but not the second? – A.R. Dec 2 '10 at 18:10 The first block isn't inside the ToolTip.
It's setting a property on TextBox, just like if you did – John Bowen Dec 2 '10 at 18:44 Oh I see, I guess that is an optical illusion from the structure of the XAML. Duh. Guess I'll look into your first suggestion then.
– A.R. Dec 3 '10 at 13:49.
Try using x:Name on the control with the tooltip, and then for the binding.
Sadly I have already tried this approach, no dice. – A.R. Dec 2 '10 at 15:56 Why not? What binding error did you get when you tried it?
– Dan Puzey Dec 7 '10 at 15:11.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.