About WPF in popup following mouse move display

Source: Internet
Author: User

Original: About WPF in popup following mouse move display

Recently in a drawing tool, there is a function that needs to be implemented, when the mouse movement, the mouse next to the display of coordinate information.

The first reaction is to think of the ToolTip, but the ToolTip has a lot of restrictions, the process of querying the data saw popup,popup more flexible than the ToolTip, the following talk about the difference between the ToolTip and the popup:

1.tooltip automatically appears, is automatically hidden, and the popup needs to set the IsOpen property, and when the Popup.staysoen property is true, the popup control remains displayed until the IsOpen property is explicitly set to False. When the Popup.staysoen property is False, the popup control disappears when the user clicks the mouse elsewhere.

2. If the popup control's IsOpen property is set to True, the popup control's Popupanimation property can be set to pop-up, placement property settings pop-up position, such as placement= "Mouse", Indicates that a "prompt box" pops up at the mouse position.

The 3.Popup control is not associated with any control, regardless of where the popup tag is defined.

The following example can be implemented when the mouse moves, the popup follows the mouse movement, and displays the coordinate information.

Popup Part code:

1 <popup name= "Pop1" staysopen= "true" allowstransparency= "true" flowdirection= "LeftToRight" 2                popupanimation= "Fade" placement= "Mouse" >3             <textblock name= "txt" text= "" width= "" height= "></textblock  >4 </Popup>

Code explanation: staysopen= "True" to make the popup appear all the time. If staysopen= "False", then the popup will not move at the last coordinate point, need to click the left mouse button to switch

To the current coordinate point.

Background code:

1  private void Touchpad_mousemove (object sender, MouseEventArgs e) 2 {3    pop1. IsOpen = False;4    pop1. IsOpen = true;5 Point    = E.getposition (inkCanv2); 6    txt. Text = ("x:" + point.) X.tostring () + "y:" + point   . Y.tostring ());//display mouse current coordinate point 7}

Explanation: Why First isopen = False and then IsOpen = False, there is an explanation below. http://bbs.csdn.net/topics/390770640

Excerpt from the words of the Great God:

"After clicking Elsewhere, Pop1 did not automatically close, but ran behind the other controls.
So you let it open, it's actually open, and it's already behind, so I can't see it.
You make it close, then open, and you run to the front. "

Http://www.cnblogs.com/TomZeng/p/6698450.html

About WPF in popup following mouse move display

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.