WPFTextbox漂亮的⽂本控件框封装
XAML代码:
<Border Background="White" CornerRadius="30,30,30,30" >
<Grid>
<Image x:Name="Rimg" Source="⽤户未选.png" Width="13.87" Height="14" Margin="28,18,354,24" Grid.Column="1"/>
<TextBox Margin="5" VerticalContentAlignment="Center" Width="280" TextWrapping="Wrap" BorderThickness="0" TabIndex="0" Grid.Column="1" Name="MyText" >
<TextBox.Resources>
<VisualBrush x:Key="HelpBrush" TileMode="None" Stretch="None" Opacity="0.3" AlignmentX="Left">
<VisualBrush.Visual>
<TextBlock Foreground="Black" FontSize="20" Name="letext" Text="{Binding ElementName=MyText,Path=Tag,Mode=TwoWay}"/> </VisualBrush.Visual>
</VisualBrush>
</TextBox.Resources>
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<Trigger Property="Text" Value="">
textbox控件边框设置<Setter Property="Background" Value="{StaticResource HelpBrush}"/>
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</Grid>
</Border>
cs代码:
private string text_tip = "";
/// <summary>
/// 设置⽂本框中默认提⽰语
/// </summary>
public string Text_tip
{
get { return text_tip; }
set
{
text_tip = value;
MyText.Tag = value;
}
}
使⽤⽅式:
<User:UserTextbox  Text_tip="请输⼊⽤户名"  x:Name="UseName"  />

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。