当该行在 DataGrid 中可见时,自动在 ItemRenderer 中显示工具提示
我有一个 AdvancedDataGrid
,它使用 HierarchicalData
以树格式显示数据。对于其中一列,我使用 AdvancedDataGridRendererProvider
在满足某些条件时有条件地显示图像。我当前正在使用 ToolTipManager
在用户将鼠标悬停在图像上时显示附加信息。
这是我想要做的:
当用户将鼠标放在图像上时,我不想显示工具提示
,而是自动显示工具提示
每当图像在 AdvancedDataGrid
中可见时。如果用户滚动浏览 AdvancedDataGrid
,toolTip
应相应地移动并跟随其图像。
示例 AdvancedDataGrid:
<mx:AdvancedDataGrid id="myAdvancedDataGrid"
displayItemsExpanded="true"
allowMultipleSelection="false"
dataProvider="{myTreeData}"
draggableColumns="false"
depthColors="{[0xD6E5FF,0xFFFFFF]}"
folderClosedIcon="{null}" folderOpenIcon="{null}" defaultLeafIcon="{null}">
<mx:columns>
<mx:AdvancedDataGridColumn id="colID" headerText="ID" dataField="myID"/>
<mx:AdvancedDataGridColumn id="colComments" headerText="Comments" dataField="comments"/>
</mx:columns>
<mx:rendererProviders>
<mx:AdvancedDataGridRendererProvider column="{colComments}" depth="2" dataField="comments" renderer="com.whatever.AdvancedDataGridCommentsRenderer" />
</mx:rendererProviders>
</mx:AdvancedDataGrid>
以及当前的 AdvancedDataGridRendererProvider:
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
paddingLeft="2" paddingRight="2" paddingTop="2"
horizontalScrollPolicy="off"
verticalScrollPolicy="off"
height="22"
horizontalAlign="center">
<fx:Script>
<![CDATA[
import mx.controls.ToolTip;
import mx.events.FlexEvent;
import mx.managers.ToolTipManager;
[Embed(source="assets/myImage.png")]
[Bindable]
private var myIcon:Class;
private var commentsToolTip:ToolTip;
override public function set data(value:Object):void
{
super.data = value;
if (value["comments"] != null)
{
if (value["comments"].toString().length > 0)
{
myImage.visible = true;
}
else
{
myImage.visible = false;
}
}
else
{
myImage.visible = false;
}
validateDisplayList();
}
private function showToolTip(evt:Event, text:String):void
{
var pt:Point = new Point(evt.currentTarget.x, evt.currentTarget.y);
// Convert the targets 'local' coordinates to 'global' -- this fixes the
// tooltips positioning within containers.
pt = evt.currentTarget.parent.contentToGlobal(pt);
commentsToolTip = ToolTipManager.createToolTip(text, pt.x, pt.y, "errorTipAbove") as ToolTip;
commentsToolTip.setStyle("borderColor", "#ff0000");
commentsToolTip.setStyle("color", "white");
var yOffset:int = commentsToolTip.height + 5;
commentsToolTip.y -= yOffset;
commentsToolTip.x -= 5;
}
// Remove the tooltip
private function killToolTip():void
{
ToolTipManager.destroyToolTip(commentsToolTip);
}
]]>
</fx:Script>
<mx:Image id="myImage"
source="{myIcon}"
mouseOver="showToolTip(event, data['comments'].toString())"
mouseOut="killToolTip()" />
</mx:HBox>
有什么建议吗?
I have an AdvancedDataGrid
that uses HierarchicalData
to display data in a tree format. For one of the columns, I'm using an AdvancedDataGridRendererProvider
to conditionally display an image if certain conditions are met. I'm currently using the ToolTipManager
to display additional information if the user mouses over the image.
Here's what I would like to do:
Instead of showing the toolTip
when the user places their mouse over the image, I would like to automatically display the toolTip
whenever the image is visible in the AdvancedDataGrid
. If the user scrolls through the AdvancedDataGrid
, the toolTip
should move and follow along with its image accordingly.
Sample AdvancedDataGrid:
<mx:AdvancedDataGrid id="myAdvancedDataGrid"
displayItemsExpanded="true"
allowMultipleSelection="false"
dataProvider="{myTreeData}"
draggableColumns="false"
depthColors="{[0xD6E5FF,0xFFFFFF]}"
folderClosedIcon="{null}" folderOpenIcon="{null}" defaultLeafIcon="{null}">
<mx:columns>
<mx:AdvancedDataGridColumn id="colID" headerText="ID" dataField="myID"/>
<mx:AdvancedDataGridColumn id="colComments" headerText="Comments" dataField="comments"/>
</mx:columns>
<mx:rendererProviders>
<mx:AdvancedDataGridRendererProvider column="{colComments}" depth="2" dataField="comments" renderer="com.whatever.AdvancedDataGridCommentsRenderer" />
</mx:rendererProviders>
</mx:AdvancedDataGrid>
And the current AdvancedDataGridRendererProvider:
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
paddingLeft="2" paddingRight="2" paddingTop="2"
horizontalScrollPolicy="off"
verticalScrollPolicy="off"
height="22"
horizontalAlign="center">
<fx:Script>
<![CDATA[
import mx.controls.ToolTip;
import mx.events.FlexEvent;
import mx.managers.ToolTipManager;
[Embed(source="assets/myImage.png")]
[Bindable]
private var myIcon:Class;
private var commentsToolTip:ToolTip;
override public function set data(value:Object):void
{
super.data = value;
if (value["comments"] != null)
{
if (value["comments"].toString().length > 0)
{
myImage.visible = true;
}
else
{
myImage.visible = false;
}
}
else
{
myImage.visible = false;
}
validateDisplayList();
}
private function showToolTip(evt:Event, text:String):void
{
var pt:Point = new Point(evt.currentTarget.x, evt.currentTarget.y);
// Convert the targets 'local' coordinates to 'global' -- this fixes the
// tooltips positioning within containers.
pt = evt.currentTarget.parent.contentToGlobal(pt);
commentsToolTip = ToolTipManager.createToolTip(text, pt.x, pt.y, "errorTipAbove") as ToolTip;
commentsToolTip.setStyle("borderColor", "#ff0000");
commentsToolTip.setStyle("color", "white");
var yOffset:int = commentsToolTip.height + 5;
commentsToolTip.y -= yOffset;
commentsToolTip.x -= 5;
}
// Remove the tooltip
private function killToolTip():void
{
ToolTipManager.destroyToolTip(commentsToolTip);
}
]]>
</fx:Script>
<mx:Image id="myImage"
source="{myIcon}"
mouseOver="showToolTip(event, data['comments'].toString())"
mouseOut="killToolTip()" />
</mx:HBox>
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果需要在显示图像时始终显示工具提示,那么它实际上并不是您需要的工具提示,在这种情况下,您应该只向项目渲染器添加画布/文本字段。
例如
,然后设置将对 myImage.visible 的调用更改为 myContainer.visible
但是,对于快速而肮脏的修复,您已经拥有了所需的一切,只需在设置数据覆盖中进行调用即可:
If the tooltip needs to be displayed all the time the image is displayed, it's not really a tooltip that you need, in that case you should just add a canvas/text field to your item renderer.
e.g.
Then set change the calls to myImage.visible to myContainer.visible
However, for the quick and dirty fix, you already have everything you need, just make the calls in the set data override: