/// <summary> /// Add a new message to the subtopic box /// </summary> /// <param name="message"></param> public void Send(Message message) { Messages.Add(message); // Create the textblock control TextBlock visualMessage = new TextBlock(); visualMessage.TextWrapping = TextWrapping.Wrap; visualMessage.Text = message.Text; visualMessage.DataContext = Contents; // Set width databinding for var widthBinding = new Binding("ActualWidth"); widthBinding.Source = Content; widthBinding.Mode = BindingMode.OneWay; visualMessage.SetBinding(TextBlock.MaxWidthProperty, widthBinding); if (message.Sender == MessageSender.Ai) { // AI messages are displayed in bold type visualMessage.FontWeight = FontWeights.Bold; } else { // User messages are displayed with a prompt character, // and in italic type visualMessage.Text = " > " + visualMessage.Text; visualMessage.FontStyle = FontStyles.Oblique; } Contents.Children.Add(visualMessage); }
/// <summary> /// Add a user message to the current subtopic box /// </summary> /// <param name="message"></param> public void UserSay(string message) { var userMessage = new Message() { Text = message, Sender = MessageSender.User }; currentSubtopic.Send(userMessage); Scroller.ScrollToBottom(); }
/// <summary> /// Add an AI message to the current subtopic box /// </summary> /// <param name="message"></param> public void AiSay(string message) { var aiMessage = new Message() { Text = message, Sender = MessageSender.Ai }; currentSubtopic.Send(aiMessage); Scroller.ScrollToBottom(); }