Search code examples
wpfimagetextbox

TextBox with image icon in WPF


I want to create TextBox with image in it. This is what I have tried:

<DockPanel Grid.Row="1" Grid.Column="1" Margin="5" >
    <Image DockPanel.Dock="Left" Source="D:\my_backup\WPF\SALIENT\SALIENT\Images\d2.PNG" Width="20" Height="20"></Image>
        <TextBox  Text="test" FontSize="16" HorizontalAlignment="Stretch" Background="Transparent"                                    
        </TextBox>
</DockPanel>

this gives me output like this: img

but i want the image inside TextBox like thisimg

anyone can help?


Solution

  • You could use this sort of implementation. you should probably make a user control out of it.

    <Border BorderBrush="Black"
                BorderThickness="2"
                VerticalAlignment="Center"
                CornerRadius="5">
    
            <StackPanel Margin="5"
                        Orientation="Horizontal">
    
                <Image Source="C:\SourceOfTheImage\Path\Image.png" 
                       Height="18"/>
                <TextBlock Text="Hello, I am a text block!"
                           Margin="3 0 0 0"/>
    
            </StackPanel>
    
    
        </Border>
    

    It looks like this for me