【发布时间】:2020-04-08 02:59:22
【问题描述】:
我的应用程序中有一个文本框,我想向其中添加图像。
在某些情况下,我想要图片和文字。
有可能吗?如何做到这一点?
谢谢。
【问题讨论】:
标签: wpf
我的应用程序中有一个文本框,我想向其中添加图像。
在某些情况下,我想要图片和文字。
有可能吗?如何做到这一点?
谢谢。
【问题讨论】:
标签: wpf
来自 XAML:
<TextBox Name="myTextBox" TextChanged="OnTextBoxTextChanged" Width="200">
<TextBox.Background>
<ImageBrush ImageSource="TextBoxBackground.gif" AlignmentX="Left" Stretch="None" />
</TextBox.Background>
</TextBox>
来自 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;
【讨论】: