Home > OS >  How to center/stretch textbox or stackpanel inside dockpanel?
How to center/stretch textbox or stackpanel inside dockpanel?

Time:07-29

I'm already tired. I've tried all the ways. I need my text to be in the middle. Before that, I centered the text by creating a separate DockPanel for it. Now I can’t do this because my interface structure is collapsing I need center Text

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="30"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <DockPanel Grid.Row="1" Grid.Column="0">
        *** MY OTHER CODE ****
    </DockPanel>
    <DockPanel  Grid.Column="0" Background="#FF79A6A6" Name="mainMenuName">
        *** MY OTHER CODE ****
    </DockPanel>


    <DockPanel LastChildFill="True" Grid.Column="1" Name="topMenu">
        <TextBlock Text="SomeText" HorizontalAlignment="Center"/>
        <StackPanel VerticalAlignment="Center" HorizontalAlignment="Right" Orientation="Horizontal">
                <TextBox x:Name="Search" />
                <Button  Width="50" Name="SearchBtn" Content="Search" HorizontalAlignment="Center"></Button>
        </StackPanel>
    </DockPanel>


    <DockPanel Name="mainContent" Background="Black" Grid.Row="1" Grid.Column="1">
        *** OTHER CODE ***
    </DockPanel>
</Grid>

CodePudding user response:

emoacht

There is no point to use DockPanel if you don't set DockPanel.Dock attached property. Move the TextBlock below of the StackPanel and then set DockPanel.Dock="Right" at that StackPanel.

  • Related