Skip to content

WatermarkTextBox

Aaron Amberman edited this page Mar 15, 2024 · 4 revisions

WPF.AA.CustomControls.WatermarkTextBox

A standard watermark TextBox control.

image

Properties

  • Watermark
    • Gets or sets the watermark.
  • WatermarkTemplate
    • Gets or sets the watermark template. (DataTemplate)

Methods

There are no public or protected methods, only inherited methods.

Events

There are no events other than inherited ones.

Usage

Usage is very similar to a normal TextBox...

<namespace:WatermarkTextBox Watermark="My watermark text" Text="..." />

<namespace:WatermarkTextBox Watermark="My image watermark" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,50,5,5" Width="200" Text="...">
    <namespace:WatermarkTextBox.WatermarkTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <Rectangle Grid.Column="0" Width="16" Height="16" Margin="0,0,5,0">
                    <Rectangle.Fill>
                        <DrawingBrush>
                            <DrawingBrush.Drawing>
                                <DrawingGroup>
                                    <DrawingGroup.Children>
                                        <GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
                                        <GeometryDrawing Brush="#FFF6F6F6" Geometry="F1M6.0003,-0.000199999999999534L6.0003,5.9998 0.000300000000000189,5.9998 0.000300000000000189,9.9998 6.0003,9.9998 6.0003,15.9998 10.0003,15.9998 10.0003,9.9998 16.0003,9.9998 16.0003,5.9998 10.0003,5.9998 10.0003,-0.000199999999999534z" />
                                        <GeometryDrawing Brush="#FFCCCCCC" Geometry="F1M15,9L9,9 9,15 7,15 7,9 1,9 1,7 7,7 7,1 9,1 9,7 15,7z" />
                                    </DrawingGroup.Children>
                                </DrawingGroup>
                            </DrawingBrush.Drawing>
                        </DrawingBrush>
                    </Rectangle.Fill>
                </Rectangle>
                <ContentPresenter Grid.Column="1" Content="{Binding}" TextElement.Foreground="LightGray" />
            </Grid>
        </DataTemplate>
    </namespace:WatermarkTextBox.WatermarkTemplate>
</namespace:WatermarkTextBox>

image

Clone this wiki locally