次の方法で共有


方法 : ポップアップのカスタム位置を指定する

更新 : 2007 年 11 月

Placement プロパティが Custom に設定されている場合に、Popup コントロールのカスタム位置を指定する方法を次の例に示します。

使用例

Placement プロパティが Custom に設定されると、PopupCustomPopupPlacementCallback デリゲートの定義済みインスタンスを呼び出します。このデリゲートは、ターゲット領域の左上隅および Popup の左上隅を基準として、表示先になり得る一連の相対位置を返します。Popup は、最も見やすい位置に配置されます。

Placement プロパティを Custom に設定することによって Popup の位置を定義する方法を次の例に示します。この例では、CustomPopupPlacementCallback デリゲートを作成して割り当てることによって Popup を配置する方法も示します。コールバック デリゲートは、2 つの CustomPopupPlacement オブジェクトを返します。最初の位置では Popup が画面の端に隠れる場合、Popup は 2 番目の位置に配置されます。

 <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;
}
popup1.CustomPopupPlacementCallback =
    new CustomPopupPlacementCallback(placePopup);

サンプル全体については、「Popup の配置のサンプル」を参照してください。

参照

概念

ポップアップの概要

参照

Popup

その他の技術情報

Popup のサンプル

ポップアップに関する「方法」トピック