共用方式為


MenuItemBinding.ToolTip 屬性

定義

取得或設定套用 MenuItemBinding 物件之功能表項目的工具提示文字。

public:
 property System::String ^ ToolTip { System::String ^ get(); void set(System::String ^ value); };
public string ToolTip { get; set; }
member this.ToolTip : string with get, set
Public Property ToolTip As String

屬性值

已套用 MenuItemBinding 之功能表項目所屬的工具提示文字。 預設為空字串 (""),表示這個屬性未設定。

範例

下列程式碼範例示範如何使用 ToolTip 屬性來指定工具提示,當使用者將滑鼠指標放在功能表項目上方時顯示。 這個工具提示會針對套用物件的每個功能表項目 MenuItemBinding 顯示。 若要讓此範例正常運作,您必須將下面的範例 XML 資料複製到名為 Menu.xml 的檔案。


<%@ page language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">
        
        <databindings>
        
          <asp:menuitembinding datamember="MapHomeNode"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            text="Static Title"
            value="Static Description"
            imageurl="~\Images\StaticImage.jpg"
            tooltip="Static ToolTip"/>
          
        </databindings>
        
      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="Menu.xml"
        runat="server"/> 

    </form>
  </body>
</html>

<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>MenuItemBinding Example</title>
</head>
<body>
    <form id="form1" runat="server">

      <h3>MenuItemBinding Example</h3>

      <asp:menu id="NavigationMenu"
        datasourceid="MenuSource"
        runat="server">
        
        <databindings>
        
          <asp:menuitembinding datamember="MapHomeNode"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="1"
            textfield="Title"
            valuefield="Description"
            imageurlfield="ImageUrl"
            tooltipfield="ToolTip"/>
          <asp:menuitembinding datamember="MapNode" 
            depth="2"
            text="Static Title"
            value="Static Description"
            imageurl="~\Images\StaticImage.jpg"
            tooltip="Static ToolTip"/>
          
        </databindings>
        
      </asp:menu>

      <asp:xmldatasource id="MenuSource"
        datafile="Menu.xml"
        runat="server"/> 

    </form>
  </body>
</html>

下列程式碼是上一個範例的網站地圖資料範例。

<MapHomeNode ImageUrl="~\Images\Home.gif"

Title="Home"

Description="Root Page"

ToolTip="Home Page">

<MapNode ImageUrl="~\Images\Music.gif"

Title="Music"

Description="Music Category"

ToolTip="Music Page">

<MapNode ImageUrl="~\Images\Classical.gif"

Title="Classical"

Description="Classical Section"

ToolTip="Classical Page"/>

<MapNode ImageUrl="~\Images\Rock.gif"

Title="Rock"

Description="Rock Section"

ToolTip="Rock Page"/>

<MapNode ImageUrl="~\Images\Jazz.gif"

Title="Jazz"

Description="Jazz Section"

ToolTip="Jazz Page"/>

</MapNode>

<MapNode ImageUrl="~\Images\Movies.gif"

Title="Movies"

Description="Movies Category"

ToolTip="Movies Page">

<MapNode ImageUrl="~\Images\Action.gif"

Title="Action"

Description="Action Section"

ToolTip="Action Page"/>

<MapNode ImageUrl="~\Images\Drama.gif"

Title="Drama"

Description="Drama Section"

ToolTip="Drama Page"/>

<MapNode ImageUrl="~\Images\Musical.gif"

Title="Musical"

Description="Musical Section"

ToolTip="Musical Page"/>

</MapNode>

</MapHomeNode>

備註

Menu 控制項系結至資料來源時,請使用 ToolTip 屬性來指定要系結至 MenuItem.ToolTip 物件的 屬性的 MenuItem 文字。 這個工具提示會與套用物件的所有功能表項目 MenuItemBinding 共用。 當使用者將滑鼠指標放在功能表項目上方時,就會顯示指定的文字。

注意

您可以直接設定其 ToolTip 屬性,以覆寫個別功能表項目的工具提示。

您也可以藉由設定 ToolTipField 屬性,將 物件的 屬性 MenuItem 系結 ToolTip 至資料來源的欄位,而不是使用這個屬性來為每個功能表項目指定相同的 ToolTip。 轉譯時, ToolTip 套用物件之每個功能表項目 MenuItemBinding 的 屬性會包含欄位的對應值。

注意

ToolTip如果同時設定 和 ToolTipField 屬性,屬性 ToolTipField 會優先使用。

設定時,這個屬性的值可以使用設計工具自動儲存到資源檔。 如需詳細資訊,請參閱 LocalizableAttribute全球化和當地語系化

適用於

另請參閱