SuperJMN
SuperJMN

Reputation: 13982

Setting the alignment of a PasswordBox in UWP

I'm trying to create a PasswordBox that looks like this

enter image description here

It has the password characters aligned to the center.

How do I modify the ControlTemplate to do this? I have seen it and it looks quite complex.

Upvotes: 2

Views: 314

Answers (1)

Romasz
Romasz

Reputation: 29792

In the template you will find a ScrollViewer called "ContentElement" which is used to display the content, just add HorizontalAlignment="Center" to it like so:

<ScrollViewer x:Name="ContentElement" 
              VerticalAlignment="Center"
              HorizontalAlignment="Center"
              AutomationProperties.AccessibilityView="Raw"
              HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
              HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
              IsTabStop="False"
              IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
              IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
              Margin="{TemplateBinding BorderThickness}"
              Padding="{TemplateBinding Padding}"
              Grid.Row="1"
              VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
              VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
              ZoomMode="Disabled"/>

Upvotes: 4

Related Questions