开发者

Centering text in passwordBox in XAML

开发者 https://www.devze.com 2023-01-09 05:50 出处:网络
I\'m trying to center the text in a PassWord box: In Blend the Text properties for align开发者_如何学Goment are all disabled.

I'm trying to center the text in a PassWord box:

In Blend the Text properties for align开发者_如何学Goment are all disabled. Is there another way to do this?

Thank you for your help.


HorizontalContentAlignment works in WPF, doesn't seem to work in Silverlight though unfortunately.

<PasswordBox Height="23" Width="400" HorizontalContentAlignment="Center" />

For Silverlight you need to tweak the template for the PasswordBox a little - you can extract the template for the password box (in Blend right click the PasswordBox, select 'Edit Template -> Edit a Copy') and then set the HorizontalAlignment on the ContentElement to {TemplateBinding HorizontalContentAlignment} - e.g.

<Border x:Name="ContentElement" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"/>

Then it seems to have the same behaviour as the WPF version and you can set HorizontalContentAlignment on the PasswordBox element as required.

0

精彩评论

暂无评论...
验证码 换一张
取 消