开发者

wpf - Dynamic complex Tooltip

I 开发者_Python百科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 ?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜