Erez
Erez

Reputation: 6446

wpf - Dynamic complex Tooltip

I want to generate a tool tip dynamically since the tooltip has to contain a grid with dynamic number of columns.

How do I do that ?

Upvotes: 0

Views: 669

Answers (1)

dcarneiro
dcarneiro

Reputation: 7150

You can create a new Popup and simulate the tooltip as that Popup.

You just have to handle this two events: MouseEnter, MouseLeave.

On Mouse Enter you can have a timer to open your popup after x seconds:

private void Canvas_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e) {
    timer = new Timer(500);
    timer.Elapsed += timer_Elapsed;
    timer.Enabled = true;
}

and on mouse leave you cancel the timer:

private void Canvas_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e) {
   timer.Elapsed -= timer_Elapsed;
   timer = null;
}

when the timer elapses, you'll use dispatcher to open the popup:

void timer_Elapsed(object sender, ElapsedEventArgs e) {
    Dispatcher.BeginInvoke(DispatcherPriority.Normal, new oolDelegate(OpenTooltip), true);
}

The Open tooltip method will open the popup:

public void OpenTooltip(bool isOpen) {
    popup.IsOpen = isOpen;
    popup.LostFocus += popup_LostFocus;
}

And you can also close it when the popup lost focus

Hope this can help

Upvotes: 1

Related Questions