Absolutely concentrated content inside the WPF Layout Panel

I need to find a way to absolutely center the contents of a LayoutPanel in WPF. I have two text block elements that should be displayed in the vertical and horizontal center of the panel, not relying on absolute heights and widths.

This is something that I can do quite easily with a single element, since any ContentControl can have this verticalContentAlignment property, but then you only have one child and I will go back to the square.

Any help would be greatly appreciated.

+3
source share
2 answers
<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="300" Width="300">
    <Grid VerticalAlignment="Center">
        <StackPanel HorizontalAlignment="Center">
            <TextBlock>First</TextBlock>
            <TextBlock>and the second</TextBlock>
        </StackPanel>
    </Grid>
</Window>

Panel, .

+15

, !

StackPanel ContentControl StackPanels VerticalAlignment Center. !

+2

Source: https://habr.com/ru/post/1703673/


All Articles