方法 : ポップアップのカスタム位置を指定する
Placement プロパティが Custom に設定されている場合に、Popup コントロールのカスタム位置を指定する方法を次の例に示します。
使用例
Placement プロパティが Custom に設定されると、Popup は CustomPopupPlacementCallback デリゲートの定義済みインスタンスを呼び出します。 このデリゲートは、ターゲット領域の左上隅および 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 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);
サンプル全体については、ポップアップ配置のサンプルを参照してください。