Somewhere recently seen and lost where ... Such a thing in general: A TextBox in which when it is empty is displayed inside a hint (so shaded) what it is for, so as not to make a separate TextBlock next to it for a hint. And disappears (hint) it is only for him to get the focus. Help code please.
2 answers
This control is in the MahApps package.
Code example:
<TextBox Controls:TextBoxHelper.Watermark="This is a textbox" /> Example in the picture:
- Is it something not built in? I do not want to drag the whole lib for TextBox. - PECHAPTER
- here's something like that, all with built-in tools: rikker.ru/textbox-s-opisaniem-i-kartinkoj-v-wpf - PECHAPPER
- @DarkByte Built-in Watermark - I did not find. I work only with this. Looks quite beautiful and there are at least some styles - Yurii Manziuk
- @DarkByte what they found - loads the project no less than the new lib. Moreover, it is beautiful and practical to get to do it, and already everything is ready. Download Only - Yurii Manziuk
- you can still try and so on stackoverflow.com/questions/833943/… - Yurii Manziuk
|
Well, in every way. For example, put an invisible textblock hit test on top and control visibility through triggers:
<Grid VerticalAlignment="Center" HorizontalAlignment="Center"> <TextBox Name="tb" Width="100"/> <TextBlock Foreground="LightGray" Text="Введите текст..." IsHitTestVisible="False" MaxWidth="{Binding ActualWidth, ElementName=tb}"> <TextBlock.Style> <Style TargetType="TextBlock"> <Setter Property="Visibility" Value="Collapsed"/> <Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding IsKeyboardFocused, ElementName=tb}" Value="False"/> <Condition Binding="{Binding Text, ElementName=tb}" Value="{x:Static sys:String.Empty}" xmlns:sys="clr-namespace:System;assembly=mscorlib"/> </MultiDataTrigger.Conditions> <Setter Property="Visibility" Value="Visible"/> </MultiDataTrigger> </Style.Triggers> </Style> </TextBlock.Style> </TextBlock> </Grid> |
