2013-07-10 37 views
3

如何對齊菜單項中的文本?我嘗試了垂直內容對齊,但沒有奏效。它僅適用於ButtonTextBox如何對齊WPF菜單項中的文本?

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

+0

顯示你嘗試過什麼。 –

+0

代碼,顯示你的代碼。 – wudzik

+5

這是粗魯的,選民必須至少指出他們爲什麼這麼做的原因。畢竟他只是一個新手,我們所有人都曾經在他的位置記住這一點。 – kiran

回答

11

試試這個

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

謝謝!它的工作原理。 –

+1

如果只有一種方法來模板 – RadioSpace

+3

我試過這個。它對我來說根本不起作用。我嘗試使用菜單項控制模板和樣式,但也沒有工作。 – jitendragarg