Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to databind the tooltip to part of a user control?
    primarykey
    data
    text
    <p>I know this question has been asked many times before, I have found a few solutions here on line, but I could not make any of them work. I have a few elements on a custom control I have, and I want to put a bound tool tip on one of them. This is what I have so far.</p> <pre><code>&lt;UserControl x:Class="DirectGraphicsControl.ColorBarView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:DirectGraphicsControl="clr-namespace:Windows.DirectGraphicsControl" mc:Ignorable="d" SizeChanged="UserControlSizeChanged" MinWidth="95"&gt; &lt;DockPanel LastChildFill="True" Width="80" x:Name="_mainDockPanel"&gt; &lt;TextBlock DockPanel.Dock="Top" x:Name="_title" x:FieldModifier="public" HorizontalAlignment="Center" Margin="0,2,0,2"/&gt; &lt;StackPanel Orientation="Vertical" DockPanel.Dock="Bottom" Margin="0,2,0,2" x:Name="_bottomLabelsRegion" x:FieldModifier="public"&gt; &lt;TextBlock x:Name="_unitName" x:FieldModifier="public" HorizontalAlignment="Center" VerticalAlignment="Bottom"/&gt; &lt;/StackPanel&gt; &lt;Grid DataContext="{Binding ElementName=_mainDockPanel.Parent, Path=MyTooltip}" &gt; &lt;DirectGraphicsControl:DirectGraphicsControl x:Name="_directGraphicsControl" MouseDoubleClick="HandleColorBarMouseDoubleClick" x:FieldModifier="public"&gt; &lt;DirectGraphicsControl:DirectGraphicsControl.ToolTip&gt; &lt;ToolTip Content="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}"/&gt; &lt;/DirectGraphicsControl:DirectGraphicsControl.ToolTip&gt; &lt;/DirectGraphicsControl:DirectGraphicsControl&gt; &lt;/Grid&gt; &lt;/DockPanel&gt; </code></pre> <p></p> <p>and this is the code behind.</p> <pre><code>/// &lt;summary&gt; /// The tool tip text /// &lt;/summary&gt; public static readonly DependencyProperty TooltipProperty = DependencyProperty.Register(Reflection.GetPropertyName&lt;ColorBarView&gt;(m =&gt; m.MyTooltip), typeof(string), typeof(ColorBarView)); /// &lt;summary&gt; /// The tool tip text /// &lt;/summary&gt; public string MyTooltip { get { return "Test from binding"; } } </code></pre> <p>The code behind property is only returning a hard coded string for now until I can actually get it working and then it will return the calculated value I would like it to. Currently on mouse over an empty box appears. When I add the text for the tooltip straight to the xaml it shows fine. This makes me think it cannot find the location of the binding.</p> <p>I am very new to wpf so any suggestions would be great.</p> <p>Thank you,</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload