how to set image in textbox in wpf

Total Post:12

Points:84
WPF 
WPF
 4010  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. 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;

      Modified On Mar-30-2018 05:21:58 AM

Answer

NEWSLETTER

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