Home > DeveloperSection > Forums > how to set image in textbox in wpf
Hank Greenberg
Hank Greenberg

Total Post:12

Points:84
Posted on    July-18-2013 2:59 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 2251  View(s)
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.



shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Points:735
Posted on    July-18-2013 11:24 PM

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;


Don't want to miss updates? Please click the below button!

Follow MindStick