Код: Выделить всё
public partial class Message : ObservableObject
{
[ObservableProperty]
public string text;
[ObservableProperty]
public bool isUser;
}
Код: Выделить всё
public class MainPageViewModel : ObservableObject
{
public ObservableCollection Messages { get; } = new();
Код: Выделить всё
var aiResponse = new Message { Text = string.Empty, IsUser = false };
Messages.Add(aiResponse);
await StreamAiResponseAsync(MessageText, aiResponse);
Код: Выделить всё
await foreach(var text in session.ChatAsync(new ChatHistory.Message(AuthorRole.User, userInput), inferenceParams))
{
responseBuilder.AppendLine(text);
aiMessage.Text = responseBuilder.ToString();
Console.Write(text);
await MainThread.InvokeOnMainThreadAsync(() =>
{
OnPropertyChanged(nameof(Messages));
// Force layout update
(Application.Current.MainPage as IView)?.InvalidateArrange();
});
}
Код: Выделить всё
...
Подробнее здесь: [url]https://stackoverflow.com/questions/78786106/ui-updating-changes-made-in-an-item-thats-in-an-observablecollection[/url]