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

时间:2015-08-31 19:50:57

标签: c# visual-studio-2013

我想在菜单项中添加工具提示。菜单上有“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;
    }

4 个答案:

答案 0 :(得分:1)

好的,我对你的班级做了一些调整。 不知何故,我感觉你混淆了控制和绑定之类的东西。 我们会看到。 ;)

我也做了一些评论,也许你可以在那时解释一下。

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.

答案 1 :(得分:0)

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

.yourclass:hover{
cursor:pointer;
}

或用jquery来定位它?

答案 2 :(得分:0)

你试过这个吗?

menuitem.ToolTip = "Delete";

通常情况下,可以存在常规MenuItem的上下文菜单。我经常使用它。 ;)

答案 3 :(得分:0)

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

menuItem.ToolTipText = "ToolTip Text Here";