首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

关于菜单样式有关问题,大神请进

2013-12-19 
关于菜单样式问题,大神请进想请教一下,想做成这样的菜单,就是横向的,一级一级的出现,如何进行处理?我如果

关于菜单样式问题,大神请进
关于菜单样式有关问题,大神请进
想请教一下,想做成这样的菜单,就是横向的,一级一级的出现,如何进行处理?
我如果用menu的ItemsPanelTemplate的话,和我想要的效果不太一样,这块应该如何处理

是应该用menu还是应该用list?
[解决办法]

    <Grid>
        <Menu Name="menu" Width="30" HorizontalAlignment="Left">
            <MenuItem Header="aaa" SubmenuOpened="MenuItem_SubmenuOpened">
                <MenuItem Header="bbb">
                    <MenuItem Header="ccc">
                        <MenuItem Header="ddd"/>
                        <MenuItem Header="fff"/>
                        <MenuItem Header="ggg"/>
                    </MenuItem>
                    <MenuItem Header="hhh"/>
                    <MenuItem Header="iii"/>
                </MenuItem>
                <MenuItem Header="jjj"/>
                <MenuItem Header="kkk"/>
            </MenuItem>
            <MenuItem Header="eee"/>
            <Menu.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Vertical"/>
                </ItemsPanelTemplate>
            </Menu.ItemsPanel>
            
        </Menu>
    </Grid>


void MenuItem_SubmenuOpened(object sender, RoutedEventArgs e)
        {
            Popup pop = GetVisualChild<Popup>(sender as MenuItem);
            pop.Placement = PlacementMode.Right;
        }

        public static T GetVisualChild<T>(Visual parent) where T : Visual
        {
            T child = default(T);
            if (parent != null)
            {
                int numVisuals = VisualTreeHelper.GetChildrenCount(parent);

                for (int i = 0; i < numVisuals; i++)
                {
                    Visual v = VisualTreeHelper.GetChild(parent, i) as Visual;
                    child = v as T;



                    if (child == null)
                    {
                        child = GetVisualChild<T>(v);
                        if (child is T)
                            return child;  
                    }
                    else
                        break;
                }
            }
            return child;
        }



关于菜单样式有关问题,大神请进[
[解决办法]
Silverlight实现菜单有很多办法,不一定要使用menue控件。使用Grid和Border就可以实现,不过麻烦些。
后台代码你可以自己写,鼠标进入时显示下一级由border组成的子菜单,border位置有参数e.position获得...
<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">

    <Grid x:Name="LayoutRoot" Background="White">
        <Border Width="100 " MaxWidth="100" Background="LightBlue" HorizontalAlignment="Left"    >
            <StackPanel >
                <Border Background="DeepSkyBlue" MouseEnter="Border_MouseEnter" MouseLeave="Border_MouseLeave" MouseLeftButtonUp="Border_MouseLeftButtonUp"  >
                    <TextBlock Name="main_menue_1" Text="菜单1" Foreground="White" Margin="10 5"></TextBlock>
                </Border>
                <Border Background="SkyBlue"  MouseEnter="Border_MouseEnter" MouseLeave="Border_MouseLeave" MouseLeftButtonUp="Border_MouseLeftButtonUp" >
                    <TextBlock Name="main_menue_2" Text="菜单1" Foreground="White" Margin="10 5"></TextBlock>
                </Border>
                <Border Background="SkyBlue"  MouseEnter="Border_MouseEnter" MouseLeave="Border_MouseLeave" MouseLeftButtonUp="Border_MouseLeftButtonUp" >
                    <TextBlock Name="main_menue_3" Text="菜单1" Foreground="White" Margin="10 5"></TextBlock>
                </Border>
                <Border Background="SkyBlue"  MouseEnter="Border_MouseEnter" MouseLeave="Border_MouseLeave" MouseLeftButtonUp="Border_MouseLeftButtonUp" >
                    <TextBlock Name="main_menue_4" Text="菜单1" Foreground="White" Margin="10 5"></TextBlock>
                </Border>
                <Border Background="SkyBlue"  MouseEnter="Border_MouseEnter" MouseLeave="Border_MouseLeave" MouseLeftButtonUp="Border_MouseLeftButtonUp" >
                    <TextBlock Name="main_menue_5" Text="菜单1" Foreground="White" Margin="10 5"></TextBlock>
                </Border>


            </StackPanel>
        </Border>
    </Grid>
</UserControl>

热点排行