在文本框中使用图像 [英] Use images in textbox

查看:43
本文介绍了在文本框中使用图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个显示十六进制值的控件(例如FFAA-CA10-56D7).现在,该值包含图像.控件的值如下:

I am creating a control that displays a hex value (For example FFAA-CA10-56D7) . Right now the value consists of images. The value of the control looks like:

对于只读控件,我没有问题.我可以根据值放置适当的图像.因此,例如,如果必须将值设置为 FF ,我将遍历字符串中的字符,然后放置相应的图像.

For a read only control I have no problems. I am able to place the appropriate images according to the value. So if I have to set the value to FF for example I will iterate through the characters on the string and then place the corresponding image.

现在问题是与读写控件有关.如果可以使用相同的字体,那就太好了.现在,当用户键入值时,我会添加图像.但这并不友好.如果用户想通过拖动鼠标选择3个字符怎么办?或者,我该如何执行Shift +箭头键组合来选择多个字符.

Now the problem is with read-write controls. It will be nice if I could use the same font. Right now I append images as the user types values. But it is not friendly. What if the user wants to select 3 characters by dragging the mouse?. Or how could I perform the shift+arrow key combination that will select multiple characters.

所以总之,我想保持控件的外观不变,并且我不想替换文本框的图像.你们推荐什么方法,以便我能保持相同的外观和感觉.

So in short I will like to keep the same look and feel of the control and I do not want to replace the images for a textbox. What approach do you guys recommend so that I can keep the same look and feel.

我尝试过的事情:

我试图用这些png创建我的自定义字体.但是未能找到合适的程序使我能够从png图像创建字体.

I tried to create my custom font from those png's. But haven't been successful on finding the right program that will enable me to create a font from png images.

推荐答案

我将通过使用带有水平StackPanel的自定义ListBox作为其ItemPanelTemplate来实现此目的,并且它的ItemsSource将是一个char列表.那么您可以提供一个包含相应图像的适当的DataTemplate(取决于char值,也许使用DataTriggers).ListBox具有Multiselection,因此您在模仿TextBox的文本选择"行为时应该没有问题,并且通过将char列表作为ItemsSouce,还可以允许复制(通过在ListBox中执行自己的EditCommands.Copy实现.

I would do this by using a custom ListBox with a Horizontal StackPanel as its ItemPanelTemplate, and its ItemsSource would be a list of char. then you could provide an appropiate DataTemplate containing the corresponding images (dependending on char value, maybe using DataTriggers). ListBox has Multiselection, so you should have no problem in imitating the Text Selection behavior of a TextBox, and by having a List of char as the ItemsSouce you can also allow Copying (by doing your own implementation of EditCommands.Copy in your ListBox.

这是您肯定要实现自己的自定义控件

This is one of those cases in which you will definitely want to implement your own Custom Control

这篇关于在文本框中使用图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆