WPF中如何让Textbox显示为一条直线
由于Textbox直接使用是一条直线 设置如下代码 可以让Textbox变为直线输入
<Style TargetType="TextBox"x:Key="UsernameTextBoxStyle"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type TextBox}"><Border x:Name="border"BorderBrush="#DDD"BorderThickness="0,0,0,1"Background="{TemplateBinding Background}"SnapsToDevicePixels="True"><Grid><TextBlock Text="账号/手机号/邮箱"Grid.Column="1"VerticalAlignment="Center"Foreground="#DDD"Name="markText"Visibility="Collapsed"FontSize="12"Margin="2,0" /><ScrollViewer x:Name="PART_ContentHost"Focusable="false"HorizontalScrollBarVisibility="Hidden"VerticalScrollBarVisibility="Hidden"Grid.Column="1"VerticalAlignment="Center"MinHeight="20" /></Grid></Border><ControlTemplate.Triggers><Trigger Property="IsMouseOver"Value="true"><Setter Property="BorderBrush"TargetName="border"Value="#0b3d90" /></Trigger><Trigger Property="IsKeyboardFocused"Value="true"><Setter Property="BorderBrush"TargetName="border"Value="#0b3d90" /></Trigger><DataTrigger Binding="{Binding Path=Text,RelativeSource={RelativeSource Mode=Self}}"Value=""><Setter Property="Visibility"TargetName="markText"Value="Visible" /></DataTrigger></ControlTemplate.Triggers></ControlTemplate></Setter.Value></Setter></Style>
Textbox 采用上面的样式 即为
<TextBox Width="90"Height="20"Text="{Binding PLCIP}"Style="{StaticResource UsernameTextBoxStyle}"/>
结果如下: