Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set two children elements with equal width, each with 50% in wpf

Tags:

wpf

IF I have two elements in a stackpanel:

<StackPanel Margin="2,2,2,2" Orientation="Horizontal">
      <TextBlock Grid.Column="0" Text="{Binding Name}" />
      <TextBox Grid.Column="1" Text="{Binding Age}"/>
</StackPanel>

How can I set them with the width equally 50%,50%?

Thanks in advance.

like image 498
olidev Avatar asked Apr 18 '12 07:04

olidev


2 Answers

To answer your comment

<Grid>
   <!-- Define Columns -->
   <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*"/>
      <ColumnDefinition Width="*"/>
   </Grid.ColumnDefinitions>    

   <TextBlock Grid.Column="0" Text="{Binding Name}" />
   <TextBox Grid.Column="1" Text="{Binding Age}"/>
</Grid>
like image 187
Rik van den Berg Avatar answered Oct 19 '22 02:10

Rik van den Berg


use UnformGrid with columns 2 or Grid with 2 columns

<UniformGrid Columns="2">
     <TextBox></TextBox>
     <TextBox></TextBox>
</UniformGrid>

or

 <Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition></ColumnDefinition>
        <ColumnDefinition></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <TextBlock Grid.Column="0"
               Text="{Binding Name}" />
    <TextBox Grid.Column="1"
             Text="{Binding Age}" />

</Grid>
like image 30
Kishore Kumar Avatar answered Oct 19 '22 02:10

Kishore Kumar