我目前正在尝试执行以下操作:如果未输入密码,则应显示文本“密码”。
但是我的模板没有显示密码,如果我使用装饰器或滚动查看器,我无法更改文本的颜色。
你有什么想法来实现这一目标吗?
这是我的样式代码:
<Style TargetType="{x:Type PasswordBox}" x:Key="Password">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="PasswordBox">
<Grid>
<PasswordBox Background="{StaticResource BrushDark}" Foreground="{StaticResource BrushTextNormal}" BorderBrush="{StaticResource BrushBorderInput}" BorderThickness="1"/>
<TextBlock HorizontalAlignment="Left"
VerticalAlignment="Center"
Text="Password"
Margin="5,0,5,0"
Foreground="#ff808080"
IsHitTestVisible="False"
x:Name="UserMessage"
Visibility="Hidden"/>
<!--<ScrollViewer Foreground="{StaticResource BrushTextNormal}" Background="{StaticResource BrushTextNormal}" x:Name="PART_ContentHost"/>-->
<!--<Decorator TextBlock.Foreground="White" x:Name="PART_ContentHost"/>-->
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Tag" Value=""/>
<Condition Property="IsKeyboardFocusWithin" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property="Visibility" TargetName="UserMessage" Value="Visible"/>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>