【发布时间】:2017-11-19 09:05:38
【问题描述】:
我使用聊天应用程序的 WPF UI(MVVM 模型),我可以在代码中显示聊天列表静态和聊天消息,但是当从数据库获取新数据时我无法同步它,应用程序与 Singleton 一起使用
#region Singleton
/// <summary>
/// A single instance of the design model
/// </summary>
///
public static ChatListDesignModel Instance => new ChatListDesignModel();
public ChatListDesignModel()
{
Items = new List<ChatListItemViewModel>
{
new ChatListItemViewModel
{
Name = "Luke1111111",
Initials = "LM",
Message = "This chat app is awesome! I bet it will be fast too",
ProfilePictureRGB = "3099c5", //fe4503 00d405 3099c5
NewContentAvailable = true,
IsSelected = true
},
};
}
此项目已显示,但是当我将新项目添加到项目时,它不会插入 UI 中
<Grid DataContext="{x:Static core:ChatListDesignModel.Instance}" Background="{StaticResource ForegroundLightBrush}">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding Items }">
定义为 ObservableCollection 的聊天消息,它也不会重新刷新或从实时数据库中获取新值
【问题讨论】:
-
Items似乎是List,而不是ObservableCollection。对吗?