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

时间:2023-01-15 15:31:28

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...

那个坏男孩使用了相当数量的私有变量,而我的子类无法访问...

5 个解决方案

#1


2  

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. You'll need to calculate those coordinates, but you might be able to do this easily without subclassing ComboBox.

如果您自己构建Menu对象,只需设置菜单对象的x,y坐标,即可将菜单放在任何位置。您需要计算这些坐标,但您可以轻松地完成此操作而无需继承ComboBox。

I am doing something similar with PopUpButton; you might find it easier to work with PopUpButton. This is based on real code from my current project:

我正在做与PopUpButton类似的事情;你可能会发现使用PopUpButton更容易。这基于我当前项目的实际代码:

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就像一个魅力。

#2


0  

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 (e.g. crowded into the lower right corner) that up is naturally coerced?

也许你可以搞乱这个房地产,所以它被置于这样的方式(例如挤在右下角),这自然是强迫的吗?

#3


0  

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代码并对其进行修改,但至少现在您已了解修改所需的位置。

#4


0  

You could set the MaxDropDownHeight, if you set it big enough Windows will automatically set the direction upwards.

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

#5


0  

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. My code just allows you to simply specify whether you want to open the menu up or down:

这激怒了我,没有尽头。我上传了一个解决方案,它是一个简单的类,它扩展了PopUpButton并删除了阶段边界检测的逻辑,因为它无论如何都失败了50%。我的代码只允许您简单地指定是要向上还是向下打开菜单:

http://gist.github.com/505255

#1


2  

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. You'll need to calculate those coordinates, but you might be able to do this easily without subclassing ComboBox.

如果您自己构建Menu对象,只需设置菜单对象的x,y坐标,即可将菜单放在任何位置。您需要计算这些坐标,但您可以轻松地完成此操作而无需继承ComboBox。

I am doing something similar with PopUpButton; you might find it easier to work with PopUpButton. This is based on real code from my current project:

我正在做与PopUpButton类似的事情;你可能会发现使用PopUpButton更容易。这基于我当前项目的实际代码:

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就像一个魅力。

#2


0  

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 (e.g. crowded into the lower right corner) that up is naturally coerced?

也许你可以搞乱这个房地产,所以它被置于这样的方式(例如挤在右下角),这自然是强迫的吗?

#3


0  

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代码并对其进行修改,但至少现在您已了解修改所需的位置。

#4


0  

You could set the MaxDropDownHeight, if you set it big enough Windows will automatically set the direction upwards.

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

#5


0  

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. My code just allows you to simply specify whether you want to open the menu up or down:

这激怒了我,没有尽头。我上传了一个解决方案,它是一个简单的类,它扩展了PopUpButton并删除了阶段边界检测的逻辑,因为它无论如何都失败了50%。我的代码只允许您简单地指定是要向上还是向下打开菜单:

http://gist.github.com/505255