[英]ASP.Net MenuItem formatting isn't being inherited by the child items
我正在以C#編程方式構建ASP.Net 4.5菜單。 頂部菜單項的格式符合我的喜好,但子項不會繼承格式。 我最關心的格式有兩件事:StaticEnableDefaultPopOutImage,它控制是否在MenuItem旁邊顯示該小箭頭,以及ItemSpacing。 前者在asp:Menu定義中設置為false,並且適用於頂部菜單項(即,沒有小箭頭顯示),但不適用於子項(小箭頭確實顯示在子項旁邊) 。 后者設置為75px,頂部菜單項之間的間距很好。 但是,子項目及其子項目被擠在一起。 我不確定如何控制此行為。 最后,菜單在母版頁中定義。 這是我在Master中的菜單代碼:
<asp:Menu runat="server" CssClass="bgcell_top_nav" ID="menuMain" Orientation="Horizontal" RenderingMode="Table" StaticEnableDefaultPopOutImage="false" Width="100%" ItemWrap="false" Height="250" DynamicVerticalOffset="8" StaticDisplayLevels="1">
<StaticMenuItemStyle ItemSpacing="75px" />
</asp:Menu>
這是我的代碼背后:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//top menu items
MenuItem ApplicationFunctionality = new MenuItem();
ApplicationFunctionality.Text = "Applications";
ApplicationFunctionality.SeparatorImageUrl = "~/images/menu-pipe.png";
this.menuMain.Items.Add(ApplicationFunctionality);
MenuItem DatabaseFunctionality = new MenuItem();
DatabaseFunctionality.Text = "Databases";
DatabaseFunctionality.SeparatorImageUrl = "~/images/menu-pipe.png";
this.menuMain.Items.Add(DatabaseFunctionality);
//sub menu items
MenuItem Application_Add = new MenuItem();
Application_Add.Text = "Add";
ApplicationFunctionality.ChildItems.Add(Application_Add);
MenuItem Application_Search = new MenuItem();
Application_Search.Text = "Search";
ApplicationFunctionality.ChildItems.Add(Application_Search);
MenuItem Application_Reports = new MenuItem();
Application_Reports.Text = "Reports";
ApplicationFunctionality.ChildItems.Add(Application_Reports);
MenuItem CreateInternalApplication = new MenuItem();
CreateInternalApplication.Text = "Internal";
CreateInternalApplication.NavigateUrl = "~/TemplateForms/ApplicationCreationTemplateForm.aspx";
Application_Add.ChildItems.Add(CreateInternalApplication);
MenuItem CreateExternalApplication = new MenuItem();
CreateExternalApplication.Text = "External";
Application_Add.ChildItems.Add(CreateExternalApplication);
}
}
我要附上一張圖片,以便人們可以看到我在說什么。
非常感謝有關如何格式化子項的任何指導。
刪除箭頭圖標:
問題在於, StaticEnableDefaultPopOutImage="false"
僅適用於靜態菜單級別,並且您具有StaticDisplayLevels="1"
。 其他兩個級別是動態的,因此您還需要DynamicEnableDefaultPopOutImage="false"
。
增加間距:
要將間距添加到動態水平,可以使用:
<DynamicMenuItemStyle ItemSpacing="75px" />
應用自定義樣式:
另外,可以將自定義樣式應用於每個菜單級別。 這樣可以更好地控制菜單的外觀。 在菜單中,使用LevelMenuItemStyles
聲明菜單項級別的LevelMenuItemStyles
。 例如,在這里我為前三個菜單項級別添加樣式類:
<asp:Menu runat="server" CssClass="bgcell_top_nav"
ID="menuMain" Orientation="Horizontal" RenderingMode="Table"
StaticEnableDefaultPopOutImage="false" Width="100%"
ItemWrap="false" Height="250" DynamicVerticalOffset="8"
StaticDisplayLevels="1">
<LevelMenuItemStyles>
<asp:MenuItemStyle CssClass="menuItemLevel1"/>
<asp:MenuItemStyle CssClass="menuItemLevel2"/>
<asp:MenuItemStyle CssClass="menuItemLevel3" />
</LevelMenuItemStyles>
</asp:Menu>
然后,您應該能夠自定義菜單的項目級別樣式,例如
.menuItemLevel2{
margin-left:7px;
}
.menuItemLevel3{
margin-left:12px;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.