2013-10-12 90 views
1

如何在WPF中用包含一些圖像的MenuItem創建一個水平菜單項目。我需要的是一個主菜單,並且會有子菜單,這些子菜單不會以垂直方式顯示,因爲它們是通常是默認的。相反,他們應該是橫向的。此外,每個MenuItem也應該包含一些圖像。任何人都可以幫助。wpf中的水平MenuItem

回答

1

我也在我的項目中做過類似的事情。我在這裏給我的代碼。

<MenuItem Style="{StaticResource HepsiSubMenuStyle}" HorizontalAlignment="Left" Width="80" Height="20" Background="Red" BorderThickness="0" Cursor="Hand" Grid.Column="1" Margin="20,0,0,0" > 

         <MenuItem.Icon> 
          <Image Source="Resource/MenuHepsi.jpg" Height="20" Width="80" VerticalAlignment="Center"/> 
         </MenuItem.Icon> 

         <MenuItem.ItemsPanel > 
          <ItemsPanelTemplate> 

           <VirtualizingStackPanel Orientation="Horizontal" Background="Red" /> 


          </ItemsPanelTemplate> 
         </MenuItem.ItemsPanel> 

         <MenuItem Style="{StaticResource HepsiSubMenuStyle}" Cursor="Hand" Width="80" Height="90" Padding="0" BorderThickness="0" > 
          <MenuItem.Icon> 
           <Image Source="/EfesBetGUI;component/Resource/Images/Footbal.png" Height="26" Width="26" HorizontalAlignment="Center" Margin="0,20,0,0" /> 
          </MenuItem.Icon> 
          <MenuItem.Header> 
           <TextBlock Text="Futbol" Foreground="White" FontSize="14" Padding="0,0,0,15"> 
           </TextBlock> 
          </MenuItem.Header> 
         </MenuItem> 
         <MenuItem Style="{StaticResource HepsiSubMenuStyle}" Cursor="Hand" Width="80" Height="90" Padding="0" BorderThickness="0" > 
          <MenuItem.Icon> 
           <Image Source="/EfesBetGUI;component/Resource/Images/BasketBall.png" Height="26" Width="26" HorizontalAlignment="Center" Margin="0,20,0,0" /> 
          </MenuItem.Icon> 
          <MenuItem.Header> 
           <TextBlock Text="Basketbol" Foreground="White" FontSize="14" Padding="0,0,0,15"> 
           </TextBlock> 
          </MenuItem.Header> 

         </MenuItem 
> 
         <MenuItem Style="{StaticResource HepsiSubMenuStyle}" Cursor="Hand" Width="80" Height="90" Padding="0" BorderThickness="0" > 
          <MenuItem.Icon> 
           <Image Source="/EfesBetGUI;component/Resource/Images/Duello.png" Height="26" Width="49" HorizontalAlignment="Center" Margin="0,20,0,0" /> 
          </MenuItem.Icon> 
          <MenuItem.Header> 
           <TextBlock Text="Duello" Foreground="White" FontSize="14" Padding="0,0,0,15"> 
           </TextBlock> 
          </MenuItem.Header> 

         </MenuItem> 
        </MenuItem>