Is there any way to stop a WPF Popup from repositioning itself when it goes off-screen?
I found this old question, but it didn’t get a proper answer to it. Is there any way to do this? I’m willing to subclass it if necessary. Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As Andrei points out, this behavior is deep inside the
Popupcontrol and hard to overcome. If you are willing to do some work it can be done by resizing and translating the content of the popup when it reaches the screen edges. For the purposes of the demonstration, we’ll focus on the left edge of the screen.If we have some XAML like this:
and code-behind like this:
then by calculating that the
Popupwould be off-screen, we can reduce the width of the content and give it a negative margin so that the portion that is on-screen is clipped to what would have appeared if thePopupwere to allow this.This would have to be extended to deal with all four edges of the screen and the possibility of multiple screens, but it demonstrates that the approach is workable.