如何将图像插入文本框wpf

时间:2021-12-15 21:24:52

My form in wpf has has to look like this: 如何将图像插入文本框wpf

我在wpf中的表格是这样的:

I need to create a textbox that contains a button and an image. The idea of this is that when I click on the image the text entered is shown as bullets . How can I do this in wpf? I don't know what tools to use.

我需要创建一个包含按钮和图像的文本框。我的想法是,当我点击图片时,输入的文字被显示为子弹。如何在wpf中做到这一点?我不知道该用什么工具。

3 个解决方案

#1


4  

Think of it as creating a user control and adding a textbox and a button to it, not as adding a button to a textbox (and note you can have the button overlap the textbox to create a similar effect).

可以把它想象成创建一个用户控件并向其添加一个文本框和一个按钮,而不是向文本框添加一个按钮(注意,可以让按钮与文本框重叠,以创建类似的效果)。

#2


4  

If you want to use it at just one place.. you can achieve this like below:

如果你只想在一个地方使用它。你可以做到以下几点:

         <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TextBox Grid.ColumnSpan="2"/>
            <Button Margin="3" Grid.Column="1" Width="30">
                <Image Source="myImage.png"/>
            </Button>
        </Grid>

#3


2  

You can make a borderless TextBox, and a button (with the image) near it, and surround them both with a border, what will give you the look anf funcionality you want.

你可以创建一个无边框的文本框和一个按钮(带有图像),并将它们都用边框包围起来,什么会给你带来你想要的外观和乐趣。

#1


4  

Think of it as creating a user control and adding a textbox and a button to it, not as adding a button to a textbox (and note you can have the button overlap the textbox to create a similar effect).

可以把它想象成创建一个用户控件并向其添加一个文本框和一个按钮,而不是向文本框添加一个按钮(注意,可以让按钮与文本框重叠,以创建类似的效果)。

#2


4  

If you want to use it at just one place.. you can achieve this like below:

如果你只想在一个地方使用它。你可以做到以下几点:

         <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <TextBox Grid.ColumnSpan="2"/>
            <Button Margin="3" Grid.Column="1" Width="30">
                <Image Source="myImage.png"/>
            </Button>
        </Grid>

#3


2  

You can make a borderless TextBox, and a button (with the image) near it, and surround them both with a border, what will give you the look anf funcionality you want.

你可以创建一个无边框的文本框和一个按钮(带有图像),并将它们都用边框包围起来,什么会给你带来你想要的外观和乐趣。