如何在WPF菜单项中对齐文本?

5
如何在菜单项中对齐文本?我尝试了垂直内容对齐,但不起作用。它仅适用于ButtonTextBox
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="652" Width="1054">
<Grid HorizontalAlignment="Center" Height="617" Width="1041">
    <Grid.Background>
        <ImageBrush ImageSource="/WpfApplication4;component/Images/hp-colorful-books-hd-105609.jpg" />
    </Grid.Background>
    <ToolBarPanel Height="42" HorizontalAlignment="Left" Margin="1,91,0,0" Name="toolBarPanel1" VerticalAlignment="Top" Width="1043" Background="#FFEEEEEE" />
    <Grid Height="472" HorizontalAlignment="Left" Margin="1,133,0,0" Name="grid1" VerticalAlignment="Top" Width="213" Background="#FFF0F0F0">
        <MenuItem Height="40" Name="menuItem1" Width="209" BorderBrush="{x:Null}" Header="Folder" FontSize="15" FontWeight="Normal" FontStretch="Expanded" FontFamily="Verdana" FontStyle="Normal" VerticalAlignment="Top" HorizontalContentAlignment="Right" FlowDirection="LeftToRight" Padding="1" Margin="1,0,3,0" VerticalContentAlignment="Bottom" >
            <MenuItem.Icon>
                <Image Source="/WpfApplication4;component/Images/Computer.png" />
            </MenuItem.Icon>
        </MenuItem>
    </Grid>
</Grid>


展示一下你尝试过的内容。 - Soner Gönül
代码,展示你的代码。 - Kamil Budziewski
7
这很粗鲁,投票者至少要说明为什么这样做。毕竟他只是一个新手,我们所有人都曾经处于他的位置,请记住这一点。 - kiran
1个回答

11

试试这个

<MenuItem.Header>
    <TextBlock Text="Header" HorizontalAlignment="Right" VerticalAlignment="Center"/>
</MenuItem.Header>

1
如果有一种方法可以将其模板化,那该多好啊。 - RadioSpace
7
我尝试过这个方法,但对我来说完全无效。我还尝试使用菜单项控件的模板和样式,但那也没有起作用。 - jitendragarg

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接