HOW TO SET IMAGE IN TEXTBOX IN WPF

Hank Greenberg

Total Post:12

Points:84
Posted by  Hank Greenberg
WPF 
WPF
 3411  View(s)
Ratings:
Rate this:
HI mindstick!

I Have TextBox In My Application That I Want to Add Image To This , Some Times

Like Microsoft Office Word I am Going To Have Both Text And Image

Is it Possible ?

If It possible How?

Thanks.

  1. shreesh chandra shukla

    Post:105

    Points:735
    Re: how to set image in textbox in wpf

    Solution!

    From XAML:

    <TextBox Name="myTextBox" TextChanged="OnTextBoxTextChanged" Width="200">

      <TextBox.Background>

        <ImageBrush ImageSource="TextBoxBackground.gif" AlignmentX="Left" Stretch="None" />

      </TextBox.Background>

    </TextBox>

    From C#

    // Create an ImageBrush.

    ImageBrush textImageBrush = new ImageBrush();

    textImageBrush.ImageSource = new BitmapImage(new Uri(@"TextBoxBackground.gif", UriKind.Relative));

    textImageBrush.AlignmentX = AlignmentX.Left;

    textImageBrush.Stretch = Stretch.None;

    // Use the brush to paint the button's background.

    myTextBox.Background = textImageBrush;

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!