Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-specify-a-custom-popup-position.md
T
Andy (Steve) De George 7f8394ee60 Update more main branch changes (#1008)
* Update build-validation.yml

* Update version-sweep.yml

* Update .acrolinx-config.edn

* Update .openpublishing.publish.config.json

* fix paths

* Update .github/workflows/build-validation.yml
2021-03-09 11:38:59 -08:00

3.0 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Specify a Custom Popup Position 03/30/2017
csharp
vb
Popup control [WPF], specifying custom position
28c24f39-d3aa-4ee2-b950-384b4a5dab92

How to: Specify a Custom Popup Position

This example shows how to specify a custom position for a xref:System.Windows.Controls.Primitives.Popup control when the xref:System.Windows.Controls.Primitives.Popup.Placement%2A property is set to xref:System.Windows.Controls.Primitives.PlacementMode.Custom.

Example

When the xref:System.Windows.Controls.Primitives.Popup.Placement%2A property is set to xref:System.Windows.Controls.Primitives.PlacementMode.Custom, the xref:System.Windows.Controls.Primitives.Popup calls a defined instance of the xref:System.Windows.Controls.Primitives.CustomPopupPlacementCallback delegate. This delegate returns a set of possible points that are relative to the top-left corner of the target area and the top-left corner of the xref:System.Windows.Controls.Primitives.Popup. The xref:System.Windows.Controls.Primitives.Popup placement occurs at the point that provides the best visibility.

The following example shows how to define the position of a xref:System.Windows.Controls.Primitives.Popup by setting the xref:System.Windows.Controls.Primitives.Popup.Placement%2A property to xref:System.Windows.Controls.Primitives.PlacementMode.Custom. It also shows how to create and assign a xref:System.Windows.Controls.Primitives.CustomPopupPlacementCallback delegate in order to position the xref:System.Windows.Controls.Primitives.Popup. The callback delegate returns two xref:System.Windows.Controls.Primitives.CustomPopupPlacement objects. If the xref:System.Windows.Controls.Primitives.Popup is hidden by a screen edge at the first position, the xref:System.Windows.Controls.Primitives.Popup is placed at the second position.

[!code-xamlPopupCustomPlacement#CustomPlacement]

[!code-csharpPopupCustomPlacement#DelegateInstance] [!code-vbPopupCustomPlacement#DelegateInstance]

[!code-csharpPopupCustomPlacement#DelegateDefinition] [!code-vbPopupCustomPlacement#DelegateDefinition]

For the complete sample, see Popup Placement Sample.

See also