I am creating a chat windows for a game, and I am using WinRT XAML for the UI.
1.What is the most efficient way to design the chat window to be able to be scrollable and handle multicolored text? At the very least each line should be able to be a separate color. At the moment I have something simple such as:
<ScrollViewer x:Name="chatViewScroller" Height="201" Width="475"> <StackPanel x:Name="chatViewContent" /> </ScrollViewer>
And then as I create new TextBlocks as I need them and add them as children to the chatViewContent. This seems like a very inefficient way of doing things.
2.When I add a new line of text, how do I update the scroller to automatically scroll to the end?
You would be better off using a ListView.
Set your ListView’s ItemTemplate to the template below
When you add a new item to your collection – it will automatically appear in the ListView.
To scroll it into view call something like this
You need the delay to wait for the ListView to add the new item.
You can check WinRT XAML Toolkit for example – specifically the ListViewExtensionsTestPage: