![](/img/trans.png)
[英]How to create numeric Textbox Custom Control with dependency Property in WPF?
[英]How to Specify CornerRadius for custom TextBox control in WPF?
我用以下代码创建了自定义ctextbox。 但我无法为此提供圆角边界。
public class FilteredTextBox : TextBox
{
public FilteredTextBox()
: base()
{
IsNumeric = false;
IsRegex = false;
IsRequired = false;
ErrorMsg = "";
RegexText = "";
HorizontalAlignment = HorizontalAlignment.Stretch;
Margin = new Thickness(0);
BorderThickness = new Thickness(1);
var border = new Border {CornerRadius = new CornerRadius(4)};
}
}
请指导我这个?
您可以使用自定义TextBox
的样式执行此操作:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.Resources>
<Style x:Key="CustomTextBoxStyle" TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Border
CornerRadius="4"
Padding="2"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1" >
<ScrollViewer Margin="0" x:Name="PART_ContentHost"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
<CustomTextBox Style="{StaticResource CustomTextBoxStyle}" Text="TextBox with CornerRadius" BorderBrush="Black" />
</Grid>
</Grid>
</Page>
希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.