The Message:
public partial class Message : ObservableObject
{
[ObservableProperty]
public string text;
[ObservableProperty]
public bool isUser;
}
The ObservableCollection:
public class MainPageViewModel : ObservableObject
{
public ObservableCollection<Message> Messages { get; } = new();
When the User sends a message(Button execution)
var aiResponse = new Message { Text = string.Empty, IsUser = false };
Messages.Add(aiResponse);
await StreamAiResponseAsync(MessageText, aiResponse);
The Streaming:
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();
});
}
XAML Code:
<CollectionView ... ItemsSource="{Binding Messages}" >
...
<Label Text="{Binding Text}"
...
The Result: it’s not working, it just doesn’t get Updated in the UI, the label stays blank. I just can’t seem to find why.
I have nothing more to say, this is something so simple just not working…
(ActivityIndicator with binding is working,
When putting the text into it before using .Add it’s working,
when trying to make changes to it, not possible?!?)