I would like to add a tooltip to an EditorButton that I added to the UltraDateTimeEditor in the ButtonsRight collection.
editor.ButtonsRight.Add(new EditorButton("btnRelative"));
How can get a tooltip for just that editor button and not the entire date time editor?
Thanks!
I was able to hack this out but I couldn't find a way to make the tooltip disappear when the mouse leaves the button. I set the AutoPopDelay to 2 sec. to work around this, so at least it goes away after a certain amount of time. You might want to submit a feature request for a ToolTipText property to be added to the EditorButton class.
Example:EditorButton button = new EditorButton();this.textEditor.ButtonsRight.Add( button );this.textEditor.CreationFilter = new CreationFilter();
private class CreationFilter : IUIElementCreationFilter{ void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { ButtonUIElementBase buttonElement = parent as ButtonUIElementBase; if ( buttonElement != null ) { ToolTipProviderUIElement tooltipElement = new ToolTipProviderUIElement( buttonElement ); tooltipElement.Rect = buttonElement.Rect; buttonElement.ChildElements.Add( tooltipElement ); } }
bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { return false; }}
private class ToolTipProviderUIElement : UIElement, IToolTipItem{ public ToolTipProviderUIElement(UIElement parent) : base(parent) { this.ToolTipItem = this; }
protected override void DrawBackColor(ref UIElementDrawParams drawParams){}
protected override bool WantsInputNotification(UIElementInputType inputType, Point point) { return inputType == UIElementInputType.MouseHover; }
ToolTipInfo IToolTipItem.GetToolTipInfo(Point mousePosition, UIElement element, UIElement previousToolTipElement, ToolTipInfo toolTipInfoDefault) { toolTipInfoDefault.AutoPopDelay = 2000; toolTipInfoDefault.ToolTipText = "it worked"; return toolTipInfoDefault; }}
A slight variation to suggested code. Instead of creating new ToolTipUIElement you can set the ToolTipItem property on the ButtonUIElement
buttonElement.ToolTipItem = new ToolTipItem("title", "text");
private class ToolTipItem : IToolTipItem { readonly string m_toolTipTitle ; readonly string m_toolTipText ; public ToolTipItem(string toolTipTitle, string toolTipText) { m_toolTipTitle = toolTipTitle; m_toolTipText = toolTipText; } ToolTipInfo IToolTipItem.GetToolTipInfo(Point mousePosition, UIElement element, UIElement previousToolTipElement, ToolTipInfo toolTipInfoDefault) { toolTipInfoDefault.AutoPopDelay = 2000; toolTipInfoDefault.ToolTipText = m_toolTipText; toolTipInfoDefault.Title = m_toolTipTitle; return toolTipInfoDefault; } }