2015-08-31 106 views
0

我想將工具提示添加到菜單項。在菜單中有「刪除」一詞,當鼠標懸停在單詞上時,我想顯示一個工具提示。我雖然使用'ToolTipService.SetToolTip();'。將工具提示添加到上下文菜單中的「Word」

這是包含在設置菜單中的項目...

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; 
    } 

回答

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

難道這簡單地使用.css做了什麼?

.yourclass:hover{ 
cursor:pointer; 
} 

或使用jQuery的目標?

+0

我正在使用c#而不是.css。 – daveskylark

0

你試過嗎?

menuitem.ToolTip = "Delete"; 

通常情況下,菜單項可以存在於常規MenuItems中。我經常使用它。 ;)

+0

當我嘗試這個'工具提示'不存在。它希望我爲它創建一個屬性或字段存根...不知道爲什麼。 – daveskylark

+0

這個contextmenuitem,它是一個自定義控件嗎? –

+0

如果contextmenuitem是一個自定義控件,您能否提供它的代碼?也許我可以在本地嘗試 –

0

上下文菜單項具有ToolTipText屬性:

menuItem.ToolTipText = "ToolTip Text Here"; 
+0

當我嘗試這個'ToolTip'不存在時。它希望我爲它創建一個屬性或字段存根...不知道爲什麼。 – daveskylark

+0

你試過「ToolTipText」嗎? –

+0

我也嘗試過'ToolTipText'。 – daveskylark

相關問題