8,756
社区成员




<Window.Resources>
<BitmapImage x:Key="UerName" CreateOptions="IgnoreImageCache" CacheOption="OnLoad" UriSource="/Test;component/Resources/UerName.jpg"/>
<Style x:Key="UserNameTemplate" TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid>
<Rectangle>
<Rectangle.Fill>
<ImageBrush Stretch="Fill" ImageSource="{DynamicResource UerName}"/>
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<TextBox x:Name="textBox" Style="{StaticResource UserNameTemplate}"/>
</Grid>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border x:Name="myTxtBorder" BorderBrush="Gray" BorderThickness="1" CornerRadius="0.5" Height="25" Width="{TemplateBinding Width}" HorizontalAlignment="Left">
<ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<!--<Setter Property="BorderBrush" TargetName="myTxtBorder" Value="Blue"></Setter>-->
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter Property="BorderBrush" TargetName="myTxtBorder" Value="SkyBlue"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
其中 ,设置Border 的背景即可。 <Window.Resources>
<BitmapImage x:Key="UerName" CreateOptions="IgnoreImageCache" CacheOption="OnLoad" UriSource="ico/Cold Fusion.ico"/>
<Style x:Key="UserNameTemplate" TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Grid>
<Rectangle>
<Rectangle.Fill>
<SolidColorBrush Color="LightBlue"/>
</Rectangle.Fill>
</Rectangle>
<ScrollViewer Name="PART_ContentHost"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<TextBox x:Name="textBox" Style="{StaticResource UserNameTemplate}"/>
</Grid>