WPF 4 TextBox 笔刷特效

     TextBox 控件是我们开发过程中必不可少的组件,它可以使应用程序方便的与用户进行文字交互。在新WPF 4 中又为TextBox 添加了两种新笔刷特效:SelectionCaret ,通过这两种特效使得TextBox 更加美观。

默认情况下TextBox 呈现出以下效果,字体为黑色、选区为蓝色、光标为黑色:

<TextBox BorderBrush="Gray" BorderThickness="3" Width="200" Height="30" />  

Default 

Default2

Selection Brush 属性

1. 字体颜色(Foreground)与选区颜色(SelectionBrush):

<TextBox BorderBrush="Gray" BorderThickness="3" Width="200" Height="30"            Foreground="Red" SelectionBrush="Green"/>  
SelectionBrush

2. 选区透明度(SelectionOpacity):

 <TextBox BorderBrush="Gray" BorderThickness="3" Width="200" Height="30"             Foreground="Red" SelectionBrush="Green" SelectionOpacity="1"/>  

SelectionOpacity

3. 渐变选区效果:

<TextBox BorderBrush="Gray" BorderThickness="3" Width="200" Height="30">      <TextBox.SelectionBrush>          <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">              <GradientStop Color="Red" Offset="0" />              <GradientStop Color="Yellow" Offset="0.2" />              <GradientStop Color="Blue" Offset="0.4" />              <GradientStop Color="Green" Offset="0.6" />              <GradientStop Color="Orchid" Offset="0.8" />              <GradientStop Color="Pink" Offset="1" />          </LinearGradientBrush>      </TextBox.SelectionBrush>  </TextBox>  
LinearGradientBrush

Caret Brush 属性

Caret 笔刷可以用来修改光标颜色:

<TextBox BorderBrush="Gray" BorderThickness="3" Width="200" Height="30"            CaretBrush="Red" />  
Caret

你可能感兴趣的:(WPF 4 TextBox 笔刷特效)