Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why there is no PlaceHolder like property in XAML TextBox

Is there any "placeholder type" property availble for textbox in xaml in windows phone 8

like image 606
John Avatar asked Apr 02 '13 08:04

John


People also ask

How do I add a watermark to a text box in WPF?

Go to the xaml code behind and add the Namespace to it, so that we can use the class WatermarkHelper. And add the following two Grids inside the LayoutRoot Grid. And then add TextBlocks and TextBoxes to the Grid. TextBlock is for the Watermark text and TextBox is for user input.

What is TextBox in WPF?

WPF TextBox control represent a control that can be used to display or edit unformatted text. The TextBox class in C# represents the control. The XAML <TextBox> element represents the TextBox control in UI. The code samples in this article show how to use XAML TextBox element to create a TextBox control in WPF and C#.


2 Answers

Try like this below code:

<TextBox x:Name="InvoiceDate" Text="" Width="300"  TextAlignment="Left" Height="30" Grid.Row="0" Grid.Column="3" Grid.ColumnSpan="2" />
                    <TextBlock IsHitTestVisible="False" Text="Men att läsa" Width="300"  TextAlignment="Left" Height="30" Grid.Row="0" Grid.Column="3" Grid.ColumnSpan="2" Padding="5, 5, 5, 5"  Foreground="LightGray">
                        <TextBlock.Style>
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="Visibility" Value="Collapsed"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Text, ElementName=InvoiceDate}" Value="">
                                        <Setter Property="Visibility" Value="Visible"/>
                                    </DataTrigger>                                    
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>
                    </TextBlock>
like image 71
Nalan Madheswaran Avatar answered Sep 24 '22 13:09

Nalan Madheswaran


There is the PhoneTextBox in the official Windows Phone Toolkit, covered here.

Sample code:

<toolkit:PhoneTextBox Hint="Password"/>

enter image description here

To add toolkit to your project : Type the following into your package manager console :
PM> Install-Package WPtoolkit
And

xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

inside <phone:PhoneApplicationPage tag in the xaml page

like image 39
Olivier Payen Avatar answered Sep 22 '22 13:09

Olivier Payen