题
我正在尝试在一个密码框中制作内容以在中心对齐时,当我们输入某些内容时,但我无法做到这一点。我已经尝试了这个链接
这是代码:
<PasswordBox Grid.Row="4" Password="{Binding Password,Mode=TwoWay}" BorderBrush="Transparent" HorizontalAlignment="Center" Margin="0" FontSize="25" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Center" Width="550" Height="90" PlaceholderText="password" >
<PasswordBox.Background>
<ImageBrush ImageSource="/Assets/Login/text-field.png" AlignmentY="Bottom"></ImageBrush>
</PasswordBox.Background>
</PasswordBox>
.
这是用于Windows Store App 。 但不确定他们是如何做的。如果有人能回答这个问题,我会感激。
解决方案
问题似乎与 passwordboxstyle 。根边框元素没有TemplateBindings。
<ControlTemplate TargetType="{x:Type PasswordBox}">
<Border x:Name="Border"
CornerRadius="2"
Padding="2"
BorderThickness="1">
<Border.Background>
<SolidColorBrush Color="{DynamicResource ControlLightColor}" />
</Border.Background>
<Border.BorderBrush>
<SolidColorBrush Color="{DynamicResource BorderMediumColor}" />
</Border.BorderBrush>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled" />
<VisualState x:Name="MouseOver" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ScrollViewer x:Name="PART_ContentHost" />
</Border>
</ControlTemplate>
.
尝试添加封装网格或将边框的横向组成它修改为如下所示:
<ControlTemplate TargetType="{x:Type PasswordBox}">
<Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}">
<Border x:Name="Border"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
CornerRadius="2"
Padding="2"
BorderThickness="1">
<Border.Background>
<SolidColorBrush Color="{DynamicResource ControlLightColor}" />
</Border.Background>
<Border.BorderBrush>
<SolidColorBrush Color="{DynamicResource BorderMediumColor}" />
</Border.BorderBrush>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled" />
<VisualState x:Name="MouseOver" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ScrollViewer x:Name="PART_ContentHost" />
</Border>
</Grid>
</ControlTemplate>
.
然后将您的样式加载为staticresource
不隶属于 StackOverflow