Make Popup.Reposition() public
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
When a `Popup` is anchored to its parent, you usually want to reposition when the parent is resized or moved. This was [discussed on StackOverflow](https://stackoverflow.com/questions/1600218/how-can-i-move-a-wpf-popup-when-its-anchor-element-moves) 12 years ago, and the proposed hacks are still valid. E.g.:
```c#
class MyPopup : Popup
{
private Window root;
public MyPopup()
{
Loaded += OnLoaded;
Unloaded += OnUnloaded;
}
private void OnLoaded(object sender, RoutedEventArgs e)
{
root = Window.GetWindow(this);
root.LocationChanged += OnRootLocationChanged;
}
private void OnRootLocationChanged(object sender, EventArgs e)
{
// HACK: Reposition() is internal. This is a way to trigger it!
var offset = this.HorizontalOffset;
this.HorizontalOffset = offset + 0.001;
this.HorizontalOffset = offset;
}
private void OnUnloaded(object sender, RoutedEventArgs e)
{
root.LocationChanged -= OnRootLocationChanged;
Loaded -= OnLoaded;
Unloaded -= OnUnloaded;
}
}
```
Obviously, the [Reposition()](https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/Popup.cs#L1923) method **should be public**. Please make it so.
Contributor guide
Assessment
This issue has not been assessed yet.