Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextBox with image icon in WPF

Tags:

image

wpf

textbox

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?

like image 817
Neelam Prajapati Avatar asked Jul 11 '16 10:07

Neelam Prajapati


1 Answers

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

like image 104
MichaelThePotato Avatar answered Sep 21 '22 15:09

MichaelThePotato