WPF 组合框下拉位置 [英] WPF ComboBox DropDown Placement

查看:25
本文介绍了WPF 组合框下拉位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ContentControl,从左到右由一个按钮、分区和一个组合框组成.我希望 ComboBox 下拉列表与控件的左侧对齐,而不是与组合框的左侧对齐.似乎无法找到有关相对位置等的文档.有人处理过这个问题吗?TIA

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 opposed to the left side of the combobox. Can't seem to find docs on Relative placement, etc. Anyone dealt with this? TIA

推荐答案

我以前做过类似的事情 - 我最终从 ComboBox 派生,获取控件的弹出部分并使用 CustomPopupPlacementCallback 来定位它.像这样……

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;
    }
}

这篇关于WPF 组合框下拉位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆