Reputation: 93
I have a TextBox in my application that I want to add an image to.
In some cases I'd like both an image and text.
Is it possible and how can this be done?
Thanks.
Upvotes: 3
Views: 9635
Reputation: 137128
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;
Upvotes: 6