How to vertically align the text in the RichEditBox in uwp, I've read the whole documentation but could not found how to achieve that.
public sealed partial class MainPage : Page
{
RichEditBox box1;
public MainPage()
{
this.InitializeComponent();
box1 = new RichEditBox()
{
Width = 500,
Height = 500,
BorderBrush = new SolidColorBrush(Colors.Blue),
BorderThickness = new Thickness(1, 1, 1, 1)
};
box1.Document.SetText(0, "asdfghjklkjhgfdsgffffffffffff\nzAsdfghjk\nlkjhgfdsasdfgh\nkjhgfdfghjkl\nlkjhgfdghjk");
box1.TextAlignment = TextAlignment.Center;
Content = box1;
}
}
As shown in the image I was able to align the text horizontally but not able to align the text vertically.

Below is the example how in excel sheet they achieved the vertical align and horizontal align both

Currently, there is built-in API that could directly change the VerticalAlignment of the text. The
TextAlignmentproperty could only change theHorizontalAlignment.You have to change the default style of the RichEditBox to get what you want.
Create a default style of the
RichEditBoxFind a
ScrollViewerobject which named ContentElement inside the style. It's the place where text are placed.Set the
VerticalAlignmentproperty of the ContentElement toCenterand the text will be placed in the center Vertically.The following XAML style is what I used for test:
The result looks like: