WPF输入框里面加文本提示

xml 复制代码
 <TextBox x:Name="txtSampleNo"  Width="265" Height="36" VerticalContentAlignment="Center"  HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"   >
     <TextBox.Resources>
         <VisualBrush x:Key="text1" Opacity="1" TileMode="None" AlignmentX="Left" Stretch="None">
             <VisualBrush.Visual>
                 <TextBlock Text="输入样品编号" FontSize="16" />
             </VisualBrush.Visual>
         </VisualBrush>
     </TextBox.Resources>
     <TextBox.Style>
         <Style TargetType="TextBox">
             <Style.Triggers>
                 <Trigger Property="Text" Value="{x:Null}">
                     <Setter Property="Background" Value="{StaticResource text1}"/>
                 </Trigger>
                 <Trigger Property="Text" Value="">
                     <Setter Property="Background" Value="{StaticResource text1}"/>
                 </Trigger>
             </Style.Triggers>
         </Style>
     </TextBox.Style>
 </TextBox>
相关推荐
小白|4 小时前
Flutter 与 OpenHarmony 深度集成:实现跨设备传感器数据协同监测系统
flutter·wpf
嗝o゚5 小时前
鸿蒙跨端协同与Flutter结合的远程办公轻应用开发
flutter·华为·wpf
豫狮恒5 小时前
OpenHarmony Flutter 分布式权限管理:跨设备可信访问与权限协同方案
分布式·flutter·wpf·openharmony
小白|5 小时前
Flutter 与 OpenHarmony 深度整合:构建跨设备统一剪贴板同步系统
flutter·wpf
He BianGu5 小时前
【笔记】在WPF中如何使用ContentPresenter 与 Generic.xaml 设置数据默认 DataTemplate
windows·笔记·wpf
小白|6 小时前
Flutter 与 OpenHarmony 深度融合:实现分布式文件共享与跨设备协同编辑系统
分布式·flutter·wpf
豫狮恒6 小时前
OpenHarmony Flutter 分布式数据持久化:跨设备数据一致性与同步方案
分布式·安全·flutter·wpf·openharmony
狮恒6 小时前
OpenHarmony Flutter 分布式能力调度:跨设备服务协同与资源共享方案
分布式·flutter·wpf·openharmony
He BianGu6 小时前
【笔记】在WPF App.cs中结合 IServiceCollection 进行 IOC 依赖注入
数据库·笔记·wpf