WPF Password cornerradius用不了
时间: 2023-11-21 20:05:04 浏览: 30
WPF PasswordBox 控件没有 CornerRadius 属性,但你可以通过修改 PasswordBox 的模板来实现圆角效果。具体步骤如下:
1. 在 XAML 中定义一个新的样式,用来修改 PasswordBox 的模板:
```xaml
<Style x:Key="RoundedPasswordBox" TargetType="{x:Type PasswordBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type PasswordBox}">
<Grid>
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="5">
<Grid>
<PasswordBox x:Name="PART_ContentHost" PasswordChar="{TemplateBinding PasswordChar}" />
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
```
2. 在 PasswordBox 控件中应用新的样式:
```xaml
<PasswordBox Style="{StaticResource RoundedPasswordBox}" />
```
这样就可以给 PasswordBox 添加圆角效果了。如果需要修改圆角的大小,只需修改 CornerRadius 属性的值即可。