WPF rounded corner textbox

Solution 1:

@Smolla had a much better answer in his comment on @Daniel Casserly's answer:

<TextBox Text="TextBox with CornerRadius">
  <TextBox.Resources>
    <Style TargetType="{x:Type Border}">
      <Setter Property="CornerRadius" Value="3"/>
    </Style>
  </TextBox.Resources>
</TextBox>

If you want all the borders of TextBoxes and ListBoxes to have rounded corners, put the style into your Window's or App's <Resources>.

Solution 2:

In WPF you can modify or recreate the look and feel of controls. So if your example what they have done is they changed the appearance of the TextBox by modifying the ControlTemplate of the existing TextBox. So to see and explore the piece of code just use the below code

<Window x:Class="WpfApplication4.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
    <ControlTemplate x:Key="TextBoxBaseControlTemplate" TargetType="{x:Type TextBoxBase}">
        <Border Background="{TemplateBinding Background}" 
                x:Name="Bd" BorderBrush="Black"
                BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="10"> 
            <ScrollViewer x:Name="PART_ContentHost"/>
        </Border>
        <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/>
                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
            </Trigger>
            <Trigger Property="Width" Value="Auto">
                <Setter Property="MinWidth" Value="100"/>
            </Trigger>
            <Trigger Property="Height" Value="Auto">
                <Setter Property="MinHeight" Value="20"/>
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
</Window.Resources>
<Grid>
    <TextBox Template="{StaticResource TextBoxBaseControlTemplate}" Height="25" Margin="5"></TextBox>
</Grid>

So we have declared a static resource in the Resource section of the Window and we have used the Resource TextBoxBaseControlTemplate in the Template property of the TextBox as Template="{StaticResource TextBoxBaseControlTemplate}" .

Templates to Customize WPF Controls just refere this document to get an idea

http://msdn.microsoft.com/en-us/magazine/cc163497.aspx