WPF ComboBox DropDown Placement

人盡茶涼 提交于 2019-12-01 12:37:06

I've done something similar before - I ended up deriving from ComboBox, getting the popup part of the control and using the CustomPopupPlacementCallback to position it. Something like this...

class MyComboBox : ComboBox
{
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();

        var popup = (Popup)Template.FindName("PART_Popup", this);
        popup.Placement = PlacementMode.Custom;
        popup.CustomPopupPlacementCallback = placePopup;
    }

    private CustomPopupPlacement[] placePopup(Size popupSize, Size targetSize, Point offset)
    {
        var placements = new[] { new CustomPopupPlacement() };
        placements[0].Point = // position the drop-down here!
        return placements;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!