in Education by
What is Content Alignment in WPF?

1 Answer

0 votes
by
The content of content controls in WPF is dealt using various properties. These two properties are HorizontalContentAlignment and VerticalContentAlignment. These properties are defined in the System.Windows.Controls.Control class that is the parent class of all controls in WPF.
 
If we create a UI with a Button and a TextBox control, the UI looks like the following figure where the default vertical and horizontal alignment of content of a Button is center. The default vertical and horizontal alignment of content of a TextBox is left and top.
 
run 
 
You want to set the contents of the Button and TextBox to bottom and right.
 
The code sets VerticalContentAlignment and HorizontalContentAlignmentproperties to bottom and right.
  1. <Grid Name="StackPanel1" Background="LightGray">  
  2.     <Button Name="Button1" Background="LightBlue" Height="45" Content="Click Me!" Margin="23,12,159,0" VerticalAlignment="Top" FontSize="16" FontWeight="Bold" VerticalContentAlignment="Bottom" HorizontalContentAlignment="Right" />  
  3.     <TextBox Height="50" Margin="26,72,74,0" Name="textBox1" VerticalAlignment="Top" Text="I am a TextBox" FontSize="16" VerticalContentAlignment="Bottom" HorizontalContentAlignment="Right" />   
  4. </Grid>  
Output that looks as in Figure:
 
Output

Related questions

0 votes
    What is the Tab Control in WPF?...
asked Apr 9, 2021 in Education by JackTerrance
0 votes
0 votes
0 votes
    What is WPF Dependency Property and how can we use?...
asked Apr 9, 2021 in Education by JackTerrance
0 votes
0 votes
0 votes
    What is Trigger and how many types of triggers in WPF?...
asked Apr 8, 2021 in Education by JackTerrance
...