关于菜单样式问题,大神请进
想请教一下,想做成这样的菜单,就是横向的,一级一级的出现,如何进行处理?
我如果用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;
}
<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>