1

如何使用包含一些图像的 MenuItem 在 wpf 中创建水平菜单项。我需要的是一个主菜单,并且会有子菜单,并且这些子菜单不会像默认情况下那样以垂直方式出现。相反,它们应该是水平的。此外,每个 MenuItem 还应该包含一些图像。任何人都可以帮忙。

4

1 回答 1

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>
于 2013-10-12T15:22:04.657 回答