Binding Tooltip to template element
-
Hey guys, I have added a TextBlock in one of my ItemTemplate, How can I bind the element parent's tooltip text to my TextBlock text for example:
I know this is wrong, because the tooltip uses ToolTipService. Thanks
There's nothing wrong with your sample there. That works perfectly well, assuming that MyParent is accessible to SubText.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
There's nothing wrong with your sample there. That works perfectly well, assuming that MyParent is accessible to SubText.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
I've try it but no luck, "MyParent" is a ListBox control, i have created a DataTemplate where SubText TextBlock is in and i've tried to bind the lisbox tooltip to the subtext text but failed Miserably.
Why not just bind the tooltip in MyParent to the same element you are binding to as SubText?
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
Hey guys, I have added a TextBlock in one of my ItemTemplate, How can I bind the element parent's tooltip text to my TextBlock text for example:
I know this is wrong, because the tooltip uses ToolTipService. Thanks
Hi You can create a custom control based on what control you are using as parent. If you are using ListBox it would be like below
public class CustomListBox : ListBox
{
public object ToolTip
{
get
{
return ToolTipService.GetToolTip(this);
}
}
}You xaml will look like below
<local:CustomListBox ItemsSource="{Binding Path=CustomerList}"
ToolTipService.ToolTip="Your Tooltip"
x:Name="lstParent">
local:CustomListBox.ItemTemplate
<DataTemplate>
<TextBlock Text="{Binding Path=ToolTip, ElementName=lstParent}" />
</DataTemplate>
</local:CustomListBox.ItemTemplate>
</local:CustomListBox>Let me know if it works. http://www.exploresilverlight.com Cheers! Vinod
Vinod