开发者

WPF ComboBox DropDown Placement

I have a ContentControl comprised fro开发者_运维技巧m 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 opposed to the left side of the combobox. Can't seem to find docs on Relative placement, etc. Anyone dealt with this? TIA


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜