You should set additionally the HorizontalAlignment
of the root MenuItem
. Like this.
<MenuItem Header="_Paramètres" Height="60" Width="188" FontWeight="Bold" FontSize="16"
HorizontalContentAlignment="Center" HorizontalAlignment="Center" >
<MenuItem Header="_Régler" Height="30" Width="188" FontWeight="Bold" FontSize="16"
Click="regler_Click_1" x:Name="regler" Background="#FF150202"/>
</MenuItem>
Setting the HorizontalAlignment
of the sub MenuItems
should not be necessary with this code.
You can find some additional information about HorizontalAlignment and HorizontalContentAlignment in the links.
Edit
Ah ok (Q&A in the comments), then the following could probably help.
<MenuItem Header="_Paramètres" Height="60" Width="188" FontWeight="Bold" FontSize="16"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" >
<MenuItem Header="_Régler" Height="30" Width="188" FontWeight="Bold" FontSize="16"
Click="regler_Click_1" x:Name="regler" Background="#FF150202"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Center"/>
</MenuItem>
Btw you should create a Style
, so that you can reuse the settings.
Edit 2
Last idea. If this isn't working, I'll never implement an UI with XAML again. ;o)
<!-- Declare this as resource -->
<Style x:Key="CenteredTextMenuItem" x:TargetType="MenuItem">
<Setter Property="HeaderTemplate">
<DataTemplate>
<TextBox Text={Binding} HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center" FontSize="16" FontWeight="Bold"/>
</DataTemplate>
</Setter>
<Setter Property="Height" Value="30"/>
<Setter Property="Width" Value="188"/>
</Style>
Usage
<MenuItem Header="_Paramètres" Height="60" Style="{StaticResource CenteredTextMenuItem}" >
<MenuItem x:Name="regler" Header="_Régler" Click="regler_Click_1"
Background="#FF150202" Style="{StaticResource CenteredTextMenuItem}"/>
</MenuItem>