为什么PasswordBox没有圆角样式?
我为 TextBox
圆角编写了一个样式代码,它起作用了。但是当我尝试相同的代码时,只需将 TargetType
字段更改为 PasswordBox
,它对 PasswordBox
不起作用。 提前致谢。
这是我的样式代码:
<Style x:Key="TextBoxTemplate" TargetType="TextBox">
<Setter Property="Background" Value="#525252"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="BorderThickness" Value="0,0,0,1"/>
<Style.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</Style.Resources>
</Style>
<Style x:Key="PasswordBoxTemplate" TargetType="PasswordBox">
<Setter Property="Background" Value="#525252"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="BorderThickness" Value="0,0,0,1"/>
<Style.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</Style.Resources>
</Style>
这是我的 XAML 样式绑定代码:
<PasswordBox Style="{DynamicResource PasswordBoxTemplate}" Name="txtPassword" FontSize="18"/>
I wrote a style code for TextBox
rounded corner and it worked. But When I tried the same code just changing the TargetType
field to PasswordBox
It didn't work for PasswordBox
.
Thanks in advance.
This is my style code:
<Style x:Key="TextBoxTemplate" TargetType="TextBox">
<Setter Property="Background" Value="#525252"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="BorderThickness" Value="0,0,0,1"/>
<Style.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</Style.Resources>
</Style>
<Style x:Key="PasswordBoxTemplate" TargetType="PasswordBox">
<Setter Property="Background" Value="#525252"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="BorderThickness" Value="0,0,0,1"/>
<Style.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="10"/>
</Style>
</Style.Resources>
</Style>
This is my XAML style binding code:
<PasswordBox Style="{DynamicResource PasswordBoxTemplate}" Name="txtPassword" FontSize="18"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PasswordBox
的特殊之处在于它重置Border
样式。它是这样实现的。您可以做的是复制PasswordBox
的默认样式并直接调整圆角半径。The
PasswordBox
is special in that it resets theBorder
style. It is implemented this way. What you can do is you can copy the default style of thePasswordBox
and adapt the corner radius directly.