在UWP中设置PasswordBox的对齐方式

时间:2017-03-15 09:23:05

标签: c# .net windows xaml uwp

我试图创建一个看起来像这样的PasswordBox

enter image description here

密码字符与中心对齐。

如何修改ControlTemplate来执行此操作?我看过它,看起来很复杂。

1 个答案:

答案 0 :(得分:3)

在模板中,您会找到一个名为“ContentElement”的ScrollViewer,用于显示内容,只需添加HorizontalAlignment="Center"即可:

<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"/>