c# - WPF - Trouble binding ToolTip text on custom user control -
i'm in process of creating simple user control; imagebutton.
i've bound image button , i've decided add tooltip. i'm having troubles. seems can hard-code text tooltip in xaml control, when it's bound it's returning empty string.
here's xaml 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's dependency property info tooltip text:
public static readonly dependencyproperty tooltiptextproperty = dependencyproperty.register("tooltiptext", typeof(string), typeof(imagebutton)); public string tooltiptext { { return this.getvalue(tooltiptextproperty) string; } set { this.setvalue(tooltiptextproperty, value); } }
and, finally, declaration of control in window:
<controls:imagebutton x:name="btnadd" source="/dacms;component/resources/plus.png" tooltiptext="add new item" click="btnadd_click" />
as mentioned before, image binds fine , i've done in same manner.
any ideas?
thanks,
sonny
edit: have working now. i've removed elementname binding , set textblock's datacontext = this
in code behind on instanciation. still, i'd know how fix in xaml, instead.
i'm unable test right now, can try:
<button.tooltip datacontext=”{binding path=placementtarget.parent.parent, relativesource={x:static relativesource.self}}" > <textblock text="{binding path=tooltiptext}" /> </button.tooltip>
you may have experiment little number of "parent" in placementtarget.
hopefully works. don't giving answers haven't tested, don't have vs on computer. :)
Comments
Post a Comment