![](/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.