2011-12-03 9 views
2

次のコードでカスタムctextboxを作成しました。しかし、私はこれのためのroundcornerの境界を提供することができません。WPFでカスタムTextBoxコントロールのCornerRadiusを指定する方法は?

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のスタイルでこれを行うことができます

答えて

7

<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> 

希望これは私がタック・オンpunker76の大きな反響にとしてこれを追加したい

1

役立ちます:

場合をあなたはこれまでに.NETで利用可能な現在のFrameworkElementオブジェクトのデフォルトスタイルを修正したいと思っていますが、これには数多くのアプローチがありますが、私はいつもこの便利なツールが好きです:

Show Me The Template

関連する問題