D
D
Denis Mashanov2016-07-21 22:33:43
XAML
Denis Mashanov, 2016-07-21 22:33:43

How to set text to center in ContentPresenter?

Help me please. I can not center vertically and horizontally the name "Properties". (
smfaBSC5jg

<ControlTemplate x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
            <Grid>
                <Border Height="22" Width="159" Name="Head">
                    <ContentPresenter ContentSource="Header" RecognizesAccessKey="True" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0" Width="159"/>
                </Border>
                <Popup IsOpen="{TemplateBinding IsSubmenuOpen}" AllowsTransparency="True" PopupAnimation="Fade" Margin="0" Placement="Bottom" VerticalOffset="-22" HorizontalOffset="159" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                    <StackPanel  IsItemsHost="True" Background="#01FFFFFF" Focusable="True" VerticalAlignment="Stretch" Margin="0" OverridesDefaultStyle="False" IsManipulationEnabled="False" AutomationProperties.IsRequiredForForm="False" SnapsToDevicePixels="False"/>
                </Popup>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsHighlighted" Value="true">
                    <Setter TargetName="Head" Property="Background" Value="#3500ACFF"/>
                    <Setter TargetName="Head" Property="BorderBrush" Value="#FF00ACFF"/>
                    <Setter TargetName="Head" Property="BorderThickness" Value="1,1,1,1"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
<MenuItem Style="{StaticResource MenuItem}" Header="Настройки">
                <MenuItem Style="{StaticResource MenuItem}" Header="Свойства"  HorizontalAlignment="Left" VerticalAlignment="Center">
                    <!--<RadioButton></RadioButton>-->
                    <MenuItem x:Name="FastDelProjectN" Style="{StaticResource MenuItem}" Header="Быстрое удаление проекта"  Click="FastDelProject" Background="#00000000" Margin="0" Padding="0"/>
                    <MenuItem x:Name="FullDelProjectN" Style="{StaticResource MenuItem}" Header="Полное удаление проекта"  Click="FullDelProject"/>
                </MenuItem>
                <MenuItem Style="{StaticResource MenuItem}" Header="О программе"  HorizontalAlignment="Left" VerticalAlignment="Center"/>
                <MenuItem Style="{StaticResource MenuItem}" Header="Выход"  Click="Exit" HorizontalAlignment="Left" VerticalAlignment="Center" Width="159"/>
            </MenuItem>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Mashanov, 2016-07-21
@LoneRay

In the menuitem, instead of the standard "Header" I use my own Header.

<MenuItem.Header>
        <TextBlock Text="Свойства" Width="159" Height="22" Padding="35,2,0,0"/>
</MenuItem.Header>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question