방법: 사용자 지정 팝업 위치 지정

이 예제에서는 Placement 속성이 Custom으로 설정될 때 Popup 컨트롤에 대한 사용자 지정 위치를 지정하는 방법을 보여줍니다.

예제

Placement 속성이 Custom으로 설정되면 Popup에서 CustomPopupPlacementCallback 대리자의 정의된 인스턴스를 호출합니다. 이 대리자는 대상 영역의 왼쪽 위 모서리와 Popup의 왼쪽 위 모서리에 상대적인 가능한 포인트 집합을 반환합니다. Popup 배치는 최상의 가시성을 제공하는 포인트에서 발생합니다.

다음 예제에서는 Placement 속성을 Popup으로 설정하여 Custom의 위치를 정의하는 방법을 보여줍니다. 또한 Popup 위치 지정을 위해 CustomPopupPlacementCallback 대리자를 만들고 할당하는 방법도 보여줍니다. 콜백 대리자는 2개의 CustomPopupPlacement 개체를 반환합니다. Popup이 첫 번째 위치의 화면 가장자리에 의해 숨겨진 경우 Popup은 두 번째 위치에 배치됩니다.

 <Popup Name="popup1"  
        PlacementTarget ="{Binding ElementName=myButton}" 
        Placement="Custom">
  <TextBlock Height="60" Width="200" 
             Background="LightGray"
             TextWrapping="Wrap">Popup positioned by using
  CustomPopupPlacement callback delegate</TextBlock>
</Popup>
public CustomPopupPlacement[] placePopup(Size popupSize,
                                           Size targetSize,
                                           Point offset)
{
    CustomPopupPlacement placement1 =
       new CustomPopupPlacement(new Point(-50, 100), PopupPrimaryAxis.Vertical);

    CustomPopupPlacement placement2 =
        new CustomPopupPlacement(new Point(10, 20), PopupPrimaryAxis.Horizontal);

    CustomPopupPlacement[] ttplaces =
            new CustomPopupPlacement[] { placement1, placement2 };
    return ttplaces;
}
Public Function placePopup(ByVal popupSize As Size, ByVal targetSize As Size, ByVal offset As Point) As CustomPopupPlacement()
    Dim placement1 As New CustomPopupPlacement(New Point(-50, 100), PopupPrimaryAxis.Vertical)

    Dim placement2 As New CustomPopupPlacement(New Point(10, 20), PopupPrimaryAxis.Horizontal)

    Dim ttplaces() As CustomPopupPlacement = { placement1, placement2 }
    Return ttplaces
End Function
popup1.CustomPopupPlacementCallback =
    new CustomPopupPlacementCallback(placePopup);
popup1.CustomPopupPlacementCallback = New CustomPopupPlacementCallback(AddressOf placePopup)

전체 샘플을 보려면 팝업 배치 샘플을 참조하세요.

참고 항목