MenuItem 内所有 subMenuItem 上的垂直旋转标签

Vertically rotated Label on all subMenuItems inside MenuItem

我的应用程序中有一个菜单,其中包含几个菜单项。我想要在所有 MenuItems 的左侧有一个垂直标签。像这样(当然有灰色背景,请原谅我的绘画技巧):

我试过这样:

    <Menu IsMainMenu="True" Grid.Row="0" Grid.ColumnSpan="3">
        <MenuItem Header="_File">
            <TextBlock Text="Type1" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,0">
                <TextBlock.LayoutTransform>
                    <RotateTransform Angle="-90"/>
                </TextBlock.LayoutTransform>
            </TextBlock>
            <MenuItem Header="_Open" Command="{Binding OpenFileCommand}" IsEnabled="{Binding CanOpenFile}"/>
            <Separator/>
            <MenuItem Header="_Save" Command="{Binding SaveFileCommand}"/>
            <MenuItem Header="_Save As" Command="{Binding SaveAsFileCommand}"/>
            <Separator/>
            <MenuItem Header="_Exit" Command="{Binding ExitAppCommand}"/>
        </MenuItem>
    </Menu>

但它会产生这样的输出:

然后我尝试通过背景图片(透明的纯文本):

    <Menu IsMainMenu="True" Grid.Row="0" Grid.ColumnSpan="3">
        <MenuItem Header="_File">
            <MenuItem.Background>
                <ImageBrush ImageSource="{Binding SelectedObjectResourcePath}"/>
            </MenuItem.Background>
            <MenuItem Header="_Open" Command="{Binding OpenFileCommand}" IsEnabled="{Binding CanOpenFile}"/>
            <Separator/>
            <MenuItem Header="_Save" Command="{Binding SaveFileCommand}"/>
            <MenuItem Header="_Save As" Command="{Binding SaveAsFileCommand}"/>
            <Separator/>
            <MenuItem Header="_Exit" Command="{Binding ExitAppCommand}"/>
        </MenuItem>
    </Menu>

但它只为第一个 menuItem 设置背景:

我认为这里使用 StackPanel(水平方向)是最好的解决方案。看一下这个。你只需要让它看起来像你想要的那样好:)

<Menu IsMainMenu="True" Grid.Row="0">
            <MenuItem Header="_File">
                <StackPanel Orientation="Horizontal">
                    <Label Content="Type1" Margin="-30" HorizontalContentAlignment="Center">
                        <Label.LayoutTransform>
                            <RotateTransform Angle="-90"/>
                        </Label.LayoutTransform>
                    </Label>
                    <StackPanel>
                        <MenuItem Header="_Open" Command="{Binding OpenFileCommand}" IsEnabled="{Binding CanOpenFile}"/>
                        <Separator/>
                        <MenuItem Header="_Save" Command="{Binding SaveFileCommand}"/>
                        <MenuItem Header="_Save As" Command="{Binding SaveAsFileCommand}"/>
                        <Separator/>
                        <MenuItem Header="_Exit" Command="{Binding ExitAppCommand}"/>
                    </StackPanel>
                </StackPanel>
            </MenuItem>
        </Menu>