c# - 如何对齐 WPF 菜单项中的文本?

标签 c# wpf text alignment

如何对齐菜单项中的文本?我尝试了垂直内容对齐,但没有用。它仅适用于 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>

最佳答案

试试这个

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

关于c# - 如何对齐 WPF 菜单项中的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17569091/

相关文章:

c# - 如何在保存时关闭 Telerik RadGrid 中的弹出窗口?

WPF 文本 block 动画

text - Electron 中的语音转文本

c# - 如果在输出中使用 "+"或不使用 "+"有什么区别?

c# - 附加属性 + 样式 -> ArgumentNullException

java - 从带有 UTF-16 BOM 字符的文件中读取文本

c# - 如何检查当前操作是否在对象范围内?

c# - .Net5 中 JArray.FromObject() 的等价物?

c# - 何时调用 EFCore OnModelCreating?

wpf - 在 WPF 中,什么是 TemplatedParent?