简体   繁体   English

Flex-有没有办法指定ComboBox的打开方向?

[英]Flex - Is there a way to specify what direction a ComboBox will open?

Maybe I should further qualify this - Is there a way to specify which direction a ComboBox will open without copying and pasting the entire ComboBox class and ripping out the code where it determines which direction it will open in... 也许我应该对此做进一步的限定-有没有一种方法可以指定ComboBox的打开方向,而无需复制和粘贴整个ComboBox类并在确定其打开方向的代码中提取代码...

I'm my specific case - I need it to open upwards - always. 我是我的特例-我需要它向上打开-总是。

UPDATE: You can't fix this by subclassing it because the function that handles the direction of the opening is: 更新:您不能通过子类化解决此问题,因为处理打开方向的函数是:

private function displayDropdown(show:Boolean, trigger:Event = null):void

And that bad boy uses a fair amount of private variables which my subclass wouldn't have access to... 那个坏男孩使用了大量的私有变量,而我的子类无法访问...

If you build up the Menu object yourself, you can place the menu anywhere you want by simply setting the x,y coordinates of the menu object. 如果您自己构建Menu对象,则只需设置菜单对象的x,y坐标即可将菜单放置在所需的任何位置。 You'll need to calculate those coordinates, but you might be able to do this easily without subclassing ComboBox. 您将需要计算这些坐标,但是无需对ComboBox进行子类化即可轻松实现。

I am doing something similar with PopUpButton; 我正在用PopUpButton做类似的事情; you might find it easier to work with PopUpButton. 您可能会发现使用PopUpButton更容易。 This is based on real code from my current project: 这是基于我当前项目中的真实代码:

private function initMenu(): void {
    var m:Menu = new Menu();
    m.dataProvider = theMenuData;
    m.addEventListener(MenuEvent.ITEM_CLICK, menuClick);
    m.showRoot = false;
    // m.x = ... <-- probably don't need to tweak this.
    // m.y = ... <-- this is really the interesting one :-)
    theMenu.popUp = m;
}
<mx:PopUpButton id="theMenu" creationComplete="initMenu()" ... />

BTW, to get the PopUpButton to act more like I wanted it (always popup, no matter where the click), setting openAlways=true in the MXML works like a charm. 顺便说一句,要使PopUpButton的行为更像我想要的那样(无论在何处单击,总是弹出,无论在哪里单击),在MXML中设置openAlways = true都像一种魅力。

I doubt it - you'd need to subclass the control (which isn't that big a deal.) 我对此表示怀疑-你需要继承的控制(这不是什么大不了的事。)

Maybe you could mess with the real estate so it's placed in such a fashion (eg crowded into the lower right corner) that up is naturally coerced? 也许您会把房地产弄得一团糟,以这种方式放置(例如挤到右下角)自然被强迫了?

I would recommend checking out this post . 我建议您查看这篇文章 Yes, you do have to grab the ComboBox code and modify it, but at least now you have an idea where the modifications need to go. 是的,您确实必须获取ComboBox代码并进行修改,但至少现在您已经知道需要进行哪些修改。

This irritated me no end. 这激怒了我。 I have uploaded a solution, its a simple Class that extends the PopUpButton and removes the logic of stage bounds detection as it failed 50% of the time anyway. 我已经上传了一个解决方案,它是一个简单的Class,它扩展了PopUpButton并删除了阶段边界检测的逻辑,因为它无论如何都在50%的时间内失败。 My code just allows you to simply specify whether you want to open the menu up or down: 我的代码仅允许您简单地指定是向上还是向下打开菜单:

http://gist.github.com/505255 http://gist.github.com/505255

您可以设置MaxDropDownHeight,如果将其设置得足够大,Windows将自动将方向设置为向上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM