다음을 통해 공유


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

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

예제

Placement 속성이 Custom으로 설정되어 있으면 PopupCustomPopupPlacementCallback 대리자의 정의된 인스턴스를 호출합니다. 이 대리자는 대상 영역의 왼쪽 위 모퉁이 및 Popup의 왼쪽 위 모퉁이를 기준으로 가능한 일련의 지점을 반환합니다. Popup은 가시도가 가장 높은 지점에 배치됩니다.

다음 예제에서는 Placement 속성을 Custom으로 설정하여 Popup의 위치를 정의하는 방법을 보여 줍니다. 또한 Popup을 배치하기 위해 CustomPopupPlacementCallback 대리자를 만들어 할당하는 방법도 보여 줍니다. 콜백 대리자는 두 개의 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 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
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;
}
            popup1.CustomPopupPlacementCallback = New CustomPopupPlacementCallback(AddressOf placePopup)
popup1.CustomPopupPlacementCallback =
    new CustomPopupPlacementCallback(placePopup);

전체 샘플을 보려면 Popup Placement 샘플을 참조하십시오.

참고 항목

참조

Popup

개념

Popup 개요

기타 리소스

팝업 방법 항목