Answers for "placeholder wpf"

0

wpf placeholder text

/*In xaml*/
<!-- Place holder text  -->
        <TextBlock IsHitTestVisible="False" Text="Change text" VerticalAlignment="Top" HorizontalAlignment="Left" TextAlignment="Left" Margin="454,352,0,0" FontSize="40" Foreground="DarkGray" Width="352" Height="47">
            <TextBlock.Style>
                <Style TargetType="{x:Type TextBlock}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Text,ElementName=/*Enter the text box to bind to*/}" Value="">
                            <Setter Property="Visibility" Value="Visible" />
                        </DataTrigger>
                    </Style.Triggers>
                    <Setter Property="Visibility" Value="Hidden" />
                </Style>
            </TextBlock.Style>
        </TextBlock>
        <!-- Place holder text end  -->
Posted by: Guest on September-03-2021
0

placeholder wpf

<TextBox
                        x:Name="tbxSeach"
                        Grid.Row="0"
                        Grid.Column="0"
                        Height="25"
                        Margin="10,0,10,0"
                        HorizontalAlignment="Stretch"
                        VerticalAlignment="Bottom"
                        VerticalContentAlignment="Center"
                        Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                        TextAlignment="Left">
                        <TextBox.Resources>
                            <VisualBrush
                                x:Key="hinttext"
                                AlignmentX="Left"
                                Stretch="None"
                                TileMode="None">
                                <VisualBrush.Visual>
                                    <TextBlock
                                        FontStyle="Italic"
                                        Foreground="#959595"
                                        Text="Search..." />
                                </VisualBrush.Visual>
                            </VisualBrush>
                        </TextBox.Resources>
                        <TextBox.Style>
                            <Style BasedOn="{StaticResource TextBoxBase}" TargetType="TextBox">
                                <Setter Property="VerticalAlignment" Value="Center" />
                                <Setter Property="FontSize" Value="12" />
                                <Setter Property="Background" Value="Transparent" />
                                <Style.Triggers>
                                    <Trigger Property="Text" Value="">
                                        <Setter Property="Background" Value="{StaticResource hinttext}" />
                                    </Trigger>

                                    <Trigger Property="Text" Value="{x:Null}">
                                        <Setter Property="Background" Value="{StaticResource hinttext}" />
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </TextBox.Style>
                    </TextBox>
Posted by: Guest on September-29-2021

Browse Popular Code Answers by Language