简体   繁体   English

WPF MenuItem垂直对齐

[英]WPF MenuItem Vertical Alignment

My questions are: 我的问题是:

  1. How can I make the menu icons larger than normal for the visually impaired? 对于视障人士,如何使菜单图标大于正常值?
  2. How can I vertically align the text within the menu bar? 如何在菜单栏中垂直对齐文本?

Below is the code I've used so far, but I can't make it to work (larger images/fonts) and vertical alignment. 下面是我到目前为止使用的代码,但我无法使其工作(较大的图像/字体)和垂直对齐。

<Menu IsMainMenu="True" Height="48" x:Name="menuMain" Margin="10,10,10,0" VerticalAlignment="Top" BorderThickness="2" Foreground="White" FontSize="16" FontWeight="Bold" >
    <Menu.Resources>
        <Style TargetType="Image">
            <Setter Property="Height" Value="20" />
            <Setter Property="Width" Value="20" />
        </Style>
    </Menu.Resources>

    <Menu.Background>
        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
            <GradientStop Color="#FF3A60AD" Offset="0.528"/>
            <GradientStop Color="#FF6A85D8" Offset="0.01"/>
            <GradientStop Color="#FF3464C4" Offset="1"/>
            <GradientStop Color="#FF202E7E" Offset="1"/>
        </LinearGradientBrush>
    </Menu.Background>

    <Menu.BitmapEffect>
        <DropShadowBitmapEffect />
    </Menu.BitmapEffect>

    <MenuItem x:Name="Exit" Header="Exit" FontWeight="Bold" Foreground="White" FontSize="16" Click="Exit_Click" HorizontalContentAlignment="Center" ToolTip="Exit Bug Off">
        <MenuItem.Icon>
            <Image Source="C:\Dropbox\Development\BugOff\BugOff\Resources\exit48.png" Width="20" Height="20" />
        </MenuItem.Icon>
    </MenuItem>

    <MenuItem x:Name="Tracker" Header="_Tracker" FontWeight="Bold" Foreground="Orange" FontSize="16" Click="Tracker_Click" HorizontalContentAlignment="Center" ToolTip="Tracker">
        <MenuItem.Icon>
            <Image Source="C:\Dropbox\Development\BugOff\BugOff\Resources\tracker48.png" Width="20" Height="20" />
        </MenuItem.Icon>

        <MenuItem Command="New" />
        <MenuItem Command="Search" />
    </MenuItem>

    <MenuItem x:Name="WIR" Header="_WIR" FontWeight="Bold" Foreground="LightGreen" FontSize="16" Click="WIR_Click" HorizontalContentAlignment="Center" ToolTip="WIR">
        <MenuItem.Icon>
            <Image Source="C:\Dropbox\Development\BugOff\BugOff\Resources\wir48.png" Width="20" Height="20" />
        </MenuItem.Icon>
    </MenuItem>

    <MenuItem x:Name="Report" Header="_Report" FontWeight="Bold" Foreground="Pink" FontSize="16" Click="Report_Click" HorizontalContentAlignment="Center" ToolTip="Report">
        <MenuItem.Icon>
            <Image Source="C:\Dropbox\Development\BugOff\BugOff\Resources\report48.png" Width="20" Height="20" />
        </MenuItem.Icon>
    </MenuItem>

    <MenuItem x:Name="Admin" Header="_Admin" FontWeight="Bold" Foreground="LightBlue" FontSize="16" Click="Admin_Click" HorizontalContentAlignment="Center" ToolTip="Admin">
        <MenuItem.Icon>
            <Image Source="C:\Dropbox\Development\BugOff\BugOff\Resources\admin48.png" Width="20" Height="20" />
        </MenuItem.Icon>
    </MenuItem>

</Menu>

You can define menu item's Header like this, you have full control over the font/image size and their alignment. 您可以像这样定义菜单项的Header ,您可以完全控制字体/图像大小及其对齐方式。

<MenuItem x:Name="Report" Click="Report_Click" HorizontalContentAlignment="Center" ToolTip="Report">
    <MenuItem.Header>
        <StackPanel Orientation="Horizontal">
            <Image Source="C:\Dropbox\Development\BugOff\BugOff\Resources\report48.png" Width="40" Height="40"/>
            <AccessText Foreground="Pink" FontWeight="Bold" FontSize="24" VerticalAlignment="Center">_Report</AccessText>
        </StackPanel>
    </MenuItem.Header>                
</MenuItem>  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM