在XAML中将passwordBox中的文本居中 [英] Centering text in passwordBox in XAML
问题描述
我正在尝试在密码"框中将文本居中:
I'm trying to center the text in a PassWord box:
在Blend中,用于对齐的Text属性全部被禁用. 还有另一种方法吗?
In Blend the Text properties for alignment are all disabled. Is there another way to do this?
谢谢您的帮助.
推荐答案
HorizontalContentAlignment可以在WPF中使用,但不幸的是,它似乎在Silverlight中不起作用.
HorizontalContentAlignment works in WPF, doesn't seem to work in Silverlight though unfortunately.
<PasswordBox Height="23" Width="400" HorizontalContentAlignment="Center" />
对于Silverlight,您需要稍微修改PasswordBox的模板-您可以提取密码框的模板(在Blend中,右键单击PasswordBox,选择编辑模板->编辑副本"),然后设置HorizontalAlignment在ContentElement上{TemplateBinding HorizontalContentAlignment}-例如
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}"/>
然后,它似乎具有与WPF版本相同的行为,并且可以根据需要在PasswordBox元素上设置HorizontalContentAlignment.
Then it seems to have the same behaviour as the WPF version and you can set HorizontalContentAlignment on the PasswordBox element as required.
这篇关于在XAML中将passwordBox中的文本居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!