I am creating some kind of chat style application.
The Listbox is getting filled by its ItemSource which ist a Binding to a List. “Message” is a custom class containing various properties. The ListBox contains a DataTemplate which is used to display the Message-Item properly.
I’ve got a few problems when I am using a ListBox:
1. The user can not select text.
2. The ListBox does not automatically scroll down when an item is getting added to the List.
I’d like to use something like a TextBox, but I just couldn’t figure out how to use some kind of DataTemplate and bind the Text-Property to a List. Of course, the text should be formattable.
Is there anything I can do to solve my problem? I thought about extending the ListBox-Control to a Auto-Scrolling one, but this wouldn’t solve my problem concerning text selection.
I found a solution.
I copied the ItemTemplate and pasted it into a new
ItemsControl-Control. After that I wrapped aScrollVieweraround theItemsControl. I added an eventhandler to theListChangedevent. Inside the eventhandler I called the ScrollToBottom-Method of the ItemsControl-Wrapping ScrollViewer which Matěj Zábský posted.To solve the problem concerning text selection, I used a TextBox with specific properties changed.
Any way to make a WPF textblock selectable?
Thank you, Rachel and Matěj.