我想让菜单项垂直居中对齐。但是VerticalAlignment不能工作,最后它看起来
<Menu Background="{x:Null}" Style="{StaticResource m_menu_Menu}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="PlusCircle" Style="{StaticResource m_top_menu_materialDesign_Farm}" Height="43" Width="45"/>
<MenuItem x:Name="m_addWork" Header="{DynamicResource loc_menu_top_Add}" />
<materialDesign:PackIcon Kind="ChevronDown" Style="{StaticResource m_top_menu_materialDesign_Farm}"/>
</StackPanel>
</Menu>

我想要冷却单元格选择,但对齐和标题项选择看起来很糟糕。如何解决垂直对齐问题?

经过一些更改后,我有:
<Style TargetType="Menu" x:Key="m_menu_Menu">
<Setter Property="FontSize" Value="18"></Setter>
<Setter Property="FontFamily" Value="Roboto"></Setter>
<Setter Property="FontWeight" Value="Bold"></Setter>
<Setter Property="Foreground" Value="White"></Setter>
</Style>
<Style TargetType="materialDesign:PackIcon" x:Key="m_top_menu_materialDesign_Farm">
<Setter Property="Width" Value="30"></Setter>
<Setter Property="Height" Value="30"></Setter>
<Setter Property="VerticalAlignment" Value="Center"></Setter>
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
<Setter Property="Foreground" Value="White"></Setter>
</Style>
<Menu Background="{x:Null}" Style="{StaticResource m_menu_Menu}" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="PlusCircle" Style="{StaticResource m_top_menu_materialDesign_Farm}" Height="43" Width="45"/>
<MenuItem x:Name="m_addWork" Header="Add" />
<materialDesign:PackIcon Kind="ChevronDown" Style="{StaticResource m_top_menu_materialDesign_Farm}"/>
</StackPanel>
</Menu>但它看起来还很丑陋:

发布于 2020-02-26 14:48:16
我用MenuItem.Header和内部StackPanel解决了我的主要问题。代码:
<Style TargetType="Menu" x:Key="m_menu_Menu">
<Setter Property="FontSize" Value="18"></Setter>
<Setter Property="FontFamily" Value="Roboto"></Setter>
<Setter Property="FontWeight" Value="Bold"></Setter>
<Setter Property="Foreground" Value="White"></Setter>
</Style>
<Style TargetType="TextBlock" x:Key="m_top_menu_TextBlock_Farm">
<Setter Property="FontSize" Value="18"></Setter>
<Setter Property="FontFamily" Value="Roboto"></Setter>
<Setter Property="FontWeight" Value="Bold"></Setter>
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="VerticalAlignment" Value="Center"></Setter>
<Setter Property="Margin" Value="0 0 10 0"></Setter>
</Style>
<Style TargetType="materialDesign:PackIcon" x:Key="m_top_menu_materialDesign_Farm">
<Setter Property="Width" Value="30"></Setter>
<Setter Property="Height" Value="30"></Setter>
<Setter Property="VerticalAlignment" Value="Center"></Setter>
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
<Setter Property="Foreground" Value="White"></Setter>
</Style>
<Menu Background="{x:Null}" Style="{StaticResource m_menu_Menu}" VerticalAlignment="Stretch">
<MenuItem x:Name="m_addWork" Height="75">
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="PlusCircle" Style="{StaticResource m_top_menu_materialDesign_Farm}" Height="43" Width="45"/>
<TextBlock Text="Add" Style="{StaticResource m_top_menu_TextBlock_Farm}"/>
<materialDesign:PackIcon Kind="ChevronDown" Style="{StaticResource m_top_menu_materialDesign_Farm}"/>
</StackPanel>
</MenuItem.Header>
</MenuItem>
</Menu>https://stackoverflow.com/questions/60402969
复制相似问题