I am currently working on a WPF project which I needed a ToolTip with a certain behavior:
- It should act like a ToolTip
- Support content template
- Appear upon hovering with a small interval
- Appear once – hovering another element with a tooltip should hide the last shown tooltip.
- Support Rich Content
The latter is marked as bold since that was the essential requirement that made me not use the ordinary WPF ToolTip.
I needed the ToolTip to hold rich content – such as clickable buttons.
This also implicates that I wanted the ToolTip to remain shown until either one of the following
- The window was moved/size changed
- The window was deactivated (E.g. Alt+Tab)
- A click was made outside the boundary of the shown tooltip
- Otherwise – Keep being shown! – Unsupported by the built-in ToolTip.
I went over and examined my possibilities along with my close friend Aelij Arbel who worked together with me on this.
The options we were considering are as follows:
1) Built-in ToolTip – As indicated above – unsuitable.
2) Context Menu – The behavior I was looking for resembled the Context-Menu behavior, so I thought about perhaps I could template the Context menu to look like I wanted and try to change it’s core Right-Click functionality but it turned out to be quite complicated and I’m unsure it’s possible.
3) Use Popup – Popup is a great thing. It allows you to place content apart from the window Visual Tree – floating.
It supports most of the ToolTip placement properties which I needed – Let the popup control the placement positioning, take a lot of pain off my back.
Obviously, the third way appeared to be the best way to go.
Good news – Popups did do the trick I needed. However, they wouldn’t work properly in some cases.
Unfortunately, bad news – It didn’t in my case.
I attached a project sample showing some behavior disfunctions in the Popup, just so you see for yourself there are issues with that.
That was the starting point of my journey – I was going to create such RichToolTipPopup behavior that would be supported in every case!
I will post about my solution in the following days.