Reputation: 297
I have below code in the XAML.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="4" Grid.RowSpan="2" Foreground="Black" Text="Username"/>
<TextBox Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" Grid.RowSpan="1" Foreground="Black" Background="AliceBlue"/>
</Grid>
When I run the above code the alignment of textblock and textbox are not same left aligned. How can I make text block and textbox with same left alignment without using margin?
Screen shot
Upvotes: 0
Views: 298
Reputation: 29792
TextBox has its own default stye and some its values you cannot normally override without changing its style. Probably you will have to change default Padding and Margin (what I see that at that link Padding = 2).
To ensure I would advise to open you Page.xaml in Blend, click on TextBox, Edit Template -> Edit a copy (here you have good screenshots). The same with TextBlock (follow the question from previous link). When you set the same padding and margin, then your elements should be aligned the same.
Upvotes: 0