C#/WPF: Place Popup Control in Center of Screen?

Joseph jun. Melettukunnel picture Joseph jun. Melettukunnel · Nov 19, 2009 · Viewed 31.5k times · Source

Does anyone know how I can place a Popup Control in the Center of the screen?

Thanks!

Answer

Tim Ridgely picture Tim Ridgely · Nov 19, 2009

Use the Placement and PlacementTarget properties to position it relative to whatever panel is at the root of the window. So if I have a Grid, StackPanel, etc. that contains all the other "stuff" in the window called MainPanel, I do something like:

<Popup
    PlacementTarget="{Binding ElementName=MainPanel}"
    Placement="Center"
>