【问题标题】:How to align text in a WPF menu item?如何对齐 WPF 菜单项中的文本?
【发布时间】:2013-07-08 06:59:32
【问题描述】:

如何对齐菜单项中的文本?我尝试了垂直内容对齐,但没有奏效。它仅适用于 Button 和 TextBox。

<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>

【问题讨论】:

  • 显示你尝试了什么。
  • 代码,显示你的代码。
  • 这很粗鲁,反对者必须至少说明他们这样做的原因。毕竟他只是一个新手,我们所有人都曾经在他的位置上记住这一点。

标签: c# wpf text alignment


【解决方案1】:

试试这个

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

【讨论】:

  • 如果有办法将其模板化
  • 我试过这个。它对我根本不起作用。我也尝试使用菜单项控件模板和样式,但也没有用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-05
相关资源
最近更新 更多