(顺便把别人的问题也带过来了,哈哈)I am looking for a way to add placeholder text to a textbox like you can with a textbox in html.试了很多种办法都不可以,功夫不负有心人,虽然这不是我写的代码,但是我觉得非常好用。好代码要分享给大家,也自己记录一下下。
<TextBox x:Name="Textbox" Height="35" Margin="0,107,202,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" HorizontalAlignment="Right" Width="385" FontSize="20" ></TextBox>
<TextBlock x:Name="Placeholder" IsHitTestVisible="False" TextWrapping="Wrap" VerticalAlignment="Top" Margin="0,112,265,0" Foreground="DarkGray" HorizontalAlignment="Right" Width="265" Height="30" FontSize="22">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Text, ElementName=Textbox}" Value="">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style><Run Text="请输入一个非嵌套的算式"/><Run Text=":"/></TextBlock>