I’m working on a simple chat application. Currently the messages are binded to a custom-styled listbox like this (simplified XAML):
<ListBox ItemsSource='{Binding MessageCollection}'> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text='{Binding Text}'/> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
Now I would like to be able to put images (like graphical smileys) into the displayed message text. Is there any way to achieve this using TextBlock (or any other standart component) or do I need to use some special control for this?
Thanks in advance
If you want the Images actually inside the text (like an emoticon), then you are going to have to do some work. This sounds like one of the few times I would actually want a User Control, the point of which would be one that scans the Text looking for emoticon values and building a Data Template on the fly.
Remember that anything you can do in XAML you can do in code, so the code I’m thinking of would follow this general idea:
I think something like this is actually what you are looking for, but if you want just an Image, then the ValueConverter suggestion would work.