将工具提示添加到“文字”在上下文菜单中

本文关键字:上下文 菜单 文字 工具提示 添加 | 更新日期: 2023-09-27 18:10:46

我想给菜单项添加一个工具提示。在菜单上有"DELETE"这个词,当鼠标停留在这个词上时,我希望显示一个工具提示。我想使用'ToolTipService.SetToolTip();'.

这是菜单中包含的项的设置…

protected virtual void SetContextMenuItems()
    {
        // -- Add condition for ReadOnly + ReadOnly Attribute to AreaEntity
        if (this.ViewMode == Common.Core.ViewModes.RealTime)
        {
            AreaEntity ae = viewModel.EntityViewContext as AreaEntity;
            if (((UserContext.Instance.IsAdmin() && (ae.Scope.Value == "global" || ae.Scope.Value == string.Empty)) ||
                    ae.OwnerPosition.Value == CoreServices.Instance.CurrentPosition.Configuration.Name)
                    && !((this.MapInstance.Parent as Grid).Parent is PIPMap))
            {
                menuItem = new ContextMenuItem();
                //menuItem.DisplayText = "Delete"; // -- Could be dynamic based off type "Edit Polygon (Circle, etc.)"
                menuItem.DisplayText = CoreServices.Instance.GetString("Delete");
                cmd = new MR.CommandBridge.Common.Command.DelegateCommand(DeleteShape, CanDelete);
                menuItem.Command = cmd;
                this.ContextMenu.MenuItems.Add(menuItem);
            }
        }
    }

方法'DeleteShape'和'CanDelete':

public void DeleteShape(object param)
    {
        EntityStore.Instance.DeleteEntity(this.ViewModel.EntityViewContext);
    }
    public bool CanDelete(object param)
    {
        GetRulesForShape();
        bool isInFilter = false;
        EntityCollection<Entity> lists = EntitySync.Instance.Cache["entityCollection"];
        foreach (Entity list in lists)
        {
            isInFilter = (list as ListEntity).FilterList.Filters.Count(a => (a.FilterType == FilterTypes.WithinZone && a.Value == this.viewModel.EntityViewContext.Uri) ||
                                                                            (a.FilterType == FilterTypes.MultipleFilter && a.Filters.Count(b => b.FilterType == FilterTypes.WithinZone && b.Value == this.viewModel.EntityViewContext.Uri) > 0)) > 0;
            if (isInFilter) break;
        }
        return !HasRules && !CoreServices.Instance.ZoneFilters.Contains(this.viewModel.Area.Uri) && gfEditor.dm != GeofenceEditor.DrawMode.DrawEdit && !isInFilter;
    }

将工具提示添加到“文字”在上下文菜单中

好的,我对你的类做了一些调整。我感觉你把控制和绑定搞混了。我们将会看到。;)

我也做了一些评论,也许你能给我一些启发。

public class ContextMenuItem : MenuItem
{
    public ContextMenuItem()
        :base()
    {
    }
    //Replace by Header
    //
    //public string DisplayText { get; set; }

    //Can this be replaced by build in CommandParameter
    //
    private Dictionary<string, object> _parameters = new Dictionary<string, object>();
    private Func<ContextMenuItem, List<ContextMenuItem>> _getMenuItems = null; 
    //Already available
    //public DelegateCommand Command { get; set; }

    //What does this function do?
    public Func<ContextMenuItem, List<ContextMenuItem>> GetMenuItems
    {
        get
        {
            return _getMenuItems;
        }
        set
        {
            _getMenuItems = value;
        }
    }

    public Dictionary<string, object> Parameters
    {
        get
        {
            return _parameters;
        }
    }
    //Can be replaced by base Items
    //
    //private List<ContextMenuItem> _menuItems = new List<ContextMenuItem>();
    //public List<ContextMenuItem> ChildMenuItems
    //{
    //    get
    //    {
    //        return _menuItems;
    //    }
    //}
    private bool _isChecked = false;
    public bool IsChecked
    {
        get { return _isChecked; }
        set { _isChecked = value; }
    }
    // -- Command or implementer could provide a handler for all commands - might be simpler for now
    // -- I think there could be a better way to route commands but I'll thin on it.

这可以简单地在。css中完成吗?

.yourclass:hover{
cursor:pointer;
}

或目标与jquery?

你试过吗?

menuitem.ToolTip = "Delete";

通常情况下,上下文菜单可以包含常规菜单项。我经常用它。div;)

上下文菜单项具有ToolTipText属性:

menuItem.ToolTipText = "ToolTip Text Here";