Freelance Project Requests Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net

WPF: Center text vertically in a text box
How to center the text in a WPF textbox
In the default, the text in an input box always appears as Top-oriented.
Solution 1:
VerticalAlignment = "Stretch" VerticalContentAlignment = "Center"
You can reach the text within a WPF-TextBox with the combination VerticalAlignment and VerticalContentAlignment.
You set the content to center and the total height with Stretch to the size of the comprehensive element like a grid row

<TextBox VerticalAlignment="Stretch" VerticalContentAlignment="Center">

Solution 2:
VerticalAlignment = "Center" and padding
You can reach the text within a WPF-TextBox with the combination VerticalAlignment and Padding.
Like VerticalAlignment = "Center" Padding = "5"
Padding causes the text field to become larger and adapt to the surrounding element.
Example entry in XAML

<TextBox VerticalAlignment="Center" Padding="5" >

XAML example:

<TextBox Name="tbxGroup_Title" Grid.Column="2" HorizontalAlignment="Stretch" Background="#FFE8FCD9" ToolTip="Caption of Folder" TextChanged="tbxGroup_Title_TextChanged" VerticalAlignment="Center" UseLayoutRounding="False" Padding="5" >

View of a textbox element with Padding and VerticalAlignment

Without padding, the text is oriented upwards

Standard textbox without VerticalAlignment:
The following XAML text for a TextBox element displays the text at the top

<TextBox Name="tbxGroup_Title" Grid.Column="2" HorizontalAlignment="Stretch">

VerticalAlignment not set

VerticalAlignment = "Stretch"

VerticalAlignement = "Top"

VerticalAlignement = "Center"

With padding and positive values

Subject: WPF and UWP
WPF Datagrid: Set Color of Row when it has no Focus
WPF Datagrid: Change the Color of Selected Row
WPF: Change Selected Row Color in DataGrid
WPF: Read SelectedItem from DataGrid with Dynamic As Anonymous Type
WPF: Elements too wide, edge Cut off
Solved: System.InvalidCastException HResult 0x80004002 in Select DataGrid
WPF: Combobox Selected Value
WPF Datagrid: Column is not displayed
WPF: Show video in preview
WPF Webbrowser: Suppress Java Errors or Set WebBrowser to Silent


Contact for Jobs, Project Requests: