Is there any way to stop a WPF Popup from repositioning itself when it goes off-screen?

后端 未结 5 1846
孤独总比滥情好
孤独总比滥情好 2021-01-04 10:33

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

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-04 10:53

    I don't think there is a way to do this. At least a clean way. If you peek to the Popup class with the Reflector, you'll find an UpdatePosition method that will adjust the location of the popup so that it stays between screen bounds. This method is called from several places, from On***Changed callbacks (OnPlacementChanged, OnVerticalOffsetChanged, etc).

    If you're really really want to get this functionality, you might have a small chance to extend the Popup class, override some of the metadata on the properties that registered with the On***Changed callbacks so that UpdatePosition never gets called, however most people will consider doing this to be pure evil, I don't recommend it either.

提交回复
热议问题