Horizontal menu?

橙三吉。 提交于 2020-05-16 07:50:34

问题


I want to create a horizontal menu across the top of my user control whose items fill the whole space horizontally. There are six items and it's one level only - so it's not really a menu as such.

Can I do this with a menu? Or am I better off with using a six column grid with a button per col, or even a horizontal stack panel? Here is what I have so far:

 <DockPanel>
    <DockPanel DockPanel.Dock="Top" KeyboardNavigation.TabNavigation="None">
        <Menu KeyboardNavigation.TabNavigation="Cycle" VerticalAlignment="Top" Background="DarkGray" Height="40">
            <MenuItem Header="_New"/>
            <MenuItem Header="_Load" />
            <MenuItem Header="_Save" />
            <MenuItem Header="_Validate" />
            <MenuItem Header="_Import" />
            <MenuItem Header="_Export"/>
        </Menu>
    </DockPanel>
</DockPanel>

回答1:


Menu derives from ItemsControl so can just switch the ItemsPanel:

 <DockPanel>
    <DockPanel DockPanel.Dock="Top" KeyboardNavigation.TabNavigation="None">
        <Menu KeyboardNavigation.TabNavigation="Cycle" VerticalAlignment="Top" Background="DarkGray" Height="40">
          <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
              <UniformGrid Rows="1"/>
            </ItemsPanelTemplate>
          </ItemsControl.ItemsPanel>

            <MenuItem Header="_New"/>
            <MenuItem Header="_Load" />
            <MenuItem Header="_Save" />
            <MenuItem Header="_Validate" />
            <MenuItem Header="_Import" />
            <MenuItem Header="_Export"/>
        </Menu>
    </DockPanel>
</DockPanel>  



回答2:


<Menu KeyboardNavigation.TabNavigation="Cycle" VerticalAlignment="Top" Background="DarkGray" Height="40">
            <MenuItem Header="File">
                <MenuItem Header="_New"/>
                <MenuItem Header="_Load" />
                <MenuItem Header="_Save" />
                <MenuItem Header="_Validate" />
                <MenuItem Header="_Import" />
                <MenuItem Header="_Export"/>
            </MenuItem>
            <MenuItem Header="Edit">
                <MenuItem Header="Cut"/>
                <MenuItem Header="Copy"/>
                <MenuItem Header="Paste" />
                </MenuItem>
        </Menu>

Hope this will help. you need to add Menu subitems within the MenuItem. it itself is o0f List type.



来源:https://stackoverflow.com/questions/10189690/horizontal-menu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!