简体   繁体   English

子项不会继承ASP.Net MenuItem格式

[英]ASP.Net MenuItem formatting isn't being inherited by the child items

I'm building an ASP.Net 4.5 menu programmatically in C#. 我正在以C#编程方式构建ASP.Net 4.5菜单。 The top menu items are formatted to my liking, but the formatting isn't being inherited by the child items. 顶部菜单项的格式符合我的喜好,但子项不会继承格式。 The formatting I'm most concerned with are two things: StaticEnableDefaultPopOutImage, which controls whether that little arrow shows up next to the MenuItem, and ItemSpacing. 我最关心的格式有两件事:StaticEnableDefaultPopOutImage,它控制是否在MenuItem旁边显示该小箭头,以及ItemSpacing。 The former is set to false in the asp:Menu definition and works for the top menu items (ie, no little arrow shows up), but fails to work for the child items (the little arrow does show up next to the child items). 前者在asp:Menu定义中设置为false,并且适用于顶部菜单项(即,没有小箭头显示),但不适用于子项(小箭头确实显示在子项旁边) 。 The latter is set to 75px, and the top menu items are nicely spaced apart. 后者设置为75px,顶部菜单项之间的间距很好。 However, the child items and their child items are crammed next to each other. 但是,子项目及其子项目被挤在一起。 I'm not sure how to control this behavior. 我不确定如何控制此行为。 Finally, the menu is defined in a Master Page. 最后,菜单在母版页中定义。 Here's my menu code in Master: 这是我在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>

And this is my code behind: 这是我的代码背后:

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

And I'm attaching a picture of what this looks like so people can see what the issues are I'm talking about. 我要附上一张图片,以便人们可以看到我在说什么。

在此处输入图片说明

Any guidance as to how to format the child items is much appreciated. 非常感谢有关如何格式化子项的任何指导。

Removing arrow icons: 删除箭头图标:

The problem is that StaticEnableDefaultPopOutImage="false" only applies to static menu levels and you have StaticDisplayLevels="1" . 问题在于, StaticEnableDefaultPopOutImage="false"仅适用于静态菜单级别,并且您具有StaticDisplayLevels="1" The other two levels are dynamic, so you also need DynamicEnableDefaultPopOutImage="false" . 其他两个级别是动态的,因此您还需要DynamicEnableDefaultPopOutImage="false"

Adding spacing: 增加间距:

For adding spacing to dynamic levels you can use: 要将间距添加到动态水平,可以使用:

<DynamicMenuItemStyle ItemSpacing="75px" />

Applying custom styles: 应用自定义样式:

Alternatively custom styles can be applied to each menu level. 另外,可以将自定义样式应用于每个菜单级别。 This would give you more control on how the menu looks. 这样可以更好地控制菜单的外观。 In your menu declare styles for menu item levels using LevelMenuItemStyles . 在菜单中,使用LevelMenuItemStyles声明菜单项级别的LevelMenuItemStyles For example here I'm adding style classes for the first 3 menu item levels: 例如,在这里我为前三个菜单项级别添加样式类:

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

Then you should be able to customize item level styles of the menu, eg 然后,您应该能够自定义菜单的项目级别样式,例如

.menuItemLevel2{
    margin-left:7px;
}
.menuItemLevel3{
    margin-left:12px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM