WPF ComboBox DropDown Placement

后端 未结 1 1522
广开言路
广开言路 2021-01-16 08:06

I have a ContentControl comprised from left to right of a Button, partition and a ComboBox. I want the ComboBox dropdown to line up with the left side of the control as opp

相关标签:
1条回答
  • 2021-01-16 08:36

    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;
        }
    }
    
    0 讨论(0)
提交回复
热议问题