Keep popup within window bounds

前端 未结 2 1266
粉色の甜心
粉色の甜心 2021-01-14 23:06

I\'m trying to display a popup under a button.

This is what it looks like now :

\"enter

相关标签:
2条回答
  • 2021-01-14 23:42

    I fixed it by setting the placement the custom:

    <views:OptionPopup x:Name="OptionsMenuPopup"
         PlacementTarget="{Binding ElementName=AdminPanel}"
         Placement="Custom"
         MinWidth="{Binding ActualWidth, ElementName=AdminPanel}"
         MaxWidth="{Binding ActualWidth, ElementName=AdminContainer}" /> 
    

    And in the constructor of my usercontrol in code behind I added

    OptionsMenuPopup.CustomPopupPlacementCallback += (Size popupSize, Size targetSize, Point offset) =>
                new[] { new CustomPopupPlacement() { Point = new Point(targetSize.Width - popupSize.Width, targetSize.Height) } }; 
    
    0 讨论(0)
  • 2021-01-14 23:52

    You could use a combination of SystemParameters.PrimaryScreenHeight and the top-left point of the Popup to calculate how much room you have, and set that as the MaxHeight and MaxWidth of the Popup's contents.

    0 讨论(0)
提交回复
热议问题