I am creating a simple user control; just ImageButton.
I have already successfully attached the image to the button, and so I decided to add a tooltip. Now I have a problem. It seems that I can hardcode the text for the tooltip in XAML for the control, but when it bound it to return an empty string.
Here is the XAML for my control:
<Button x:Class="BCOCB.DACMS.Controls.ImageButton" 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" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Name="this" Style="{StaticResource DisabledButton}"> <Image Source="{Binding ElementName=this, Path=Source}" /> <Button.ToolTip> <TextBlock Text="{Binding ElementName=this, Path=ToolTipText}" /> </Button.ToolTip> </Button>
And here is the dependency property information for the tooltip text:
public static readonly DependencyProperty ToolTipTextProperty = DependencyProperty.Register("ToolTipText", typeof(string), typeof(ImageButton)); public string ToolTipText { get { return this.GetValue(ToolTipTextProperty) as string; } set { this.SetValue(ToolTipTextProperty, value); } }
And finally, the control declaration in my window:
<controls:ImageButton x:Name="btnAdd" Source="/DACMS;component/Resources/plus.png" ToolTipText="Add New Item" Click="btnAdd_Click" />
As I mentioned earlier, the image is perfectly linked, and I did it exactly the same.
Any ideas?
Thanks,
Sonny
EDITOR: I am working now. I removed the ElementName from the binding and set TextBlock DataContext = this to the code behind the instanciation. However, I would like to know how to fix this in XAML.
source share