Open aherrick opened 6 years ago
Tooltip expects a string value, not a datatemplate. That's how WPF works. you will need anything else if you want do display more than text
@jeremyVignelles I do just want to display text... however how can I just include a string value considering I'm using Data Binding?
I've tried something like this but it doesn't work.
<Setter Property="ToolTip" Value="{Binding Header}"/>
It should work that way. It depends on what is your DataContext. You should have a message in the output window of Visual studio.
See also : https://www.wpf-tutorial.com/data-binding/debugging/
It doesn't work that way as it has no context of the DataType:
See how HeaderItemTemplate
and ContentTemplate
are being set. When I just reference
<Setter Property="ToolTip" Value="{Binding Header}"/>
It doesn't have:
<DataTemplate DataType="{x:Type local:TabContent}">
Oh, I see where your problem is: You are trying to set a Tooltip on the TabablzControl itself, instead of each tab.
Try to remove this code:
<Setter Property="ToolTip">
<Setter.Value>
<DataTemplate DataType="{x:Type local:TabContent}">
<TextBlock Text="{Binding Header}" />
</DataTemplate>
</Setter.Value>
</Setter>
because <TextBlock Text="{Binding Header}" Width="200" ToolTip="{Binding Header}" />
should be enough. You will need to put your mouse on the text however.
You can also add a container around your text block that will hold the tooltip.
Thanks for the thoughts but no, having ToolTip
on the TextBlock
doesn't display anything.
I'm only able to get the ToolTip
to display anything is using the ToolTip
Property.
Any thoughts how I can still use the property?
Yeah, but then it would apply to the whole tabs collection, so that's not what you want.
You will want to do your work inside HeaderItemTemplate. try to wrap your text block inside a Grid or a Border with a background color and put your tooltip on that
I'm trying something like you suggested but it's not working:
<Setter Property="HeaderItemTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type local:TabContent}">
<Grid Grid.Row="1" ToolTipService.ShowDuration="5000">
<TextBlock Text="{Binding Header}" Width="200" />
<Grid.ToolTip>
<ToolTip>
<TextBlock Text="{Binding Path=Header}" TextTrimming="CharacterEllipsis" TextWrapping="Wrap" />
</ToolTip>
</Grid.ToolTip>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
@jeremyVignelles Any thoughts here? This is the sample project I am basing my testing off. How would you get ToolTip to work here:
https://github.com/ButchersBoy/DragablzSamplez/blob/master/MahAppsWindowApp/App.xaml
I have a basic Style setup like the following. I want to bind to Header property.
When I run the App, this is what I see for the ToolTip:
System.Windows.DataTemplate