public void StartLoad(bool isHavePastMessage) { Messages = new ObservableCollection <Message>(); MessagesContainer.OpenContainer(Name); List <ChatMessageDTO> chatMessagesServer = new List <ChatMessageDTO>(); if (isHavePastMessage) { (List <ChatMessageDTO>, int, int)data = _serverWorker.GetMessagesStartWithPastMessage(); chatMessagesServer = data.Item1; _topID = chatMessagesServer[0].Id; for (int i = 0; i < data.Item3; i++) { Messages.Add(new Message { Id = chatMessagesServer[i].Id, SenderName = chatMessagesServer[i].SenderName, DateSend = chatMessagesServer[i].DateSend, SendMessage = chatMessagesServer[i].SendMessage, IsItMe = chatMessagesServer[i].SenderName == Name }); AddNewMessageInContainerAndUpdateDateSend(); } if (chatMessagesServer.Count > data.Item3) { _typeOfSource = 1; MessagesLoadAsync(chatMessagesServer.Skip(data.Item3).ToList(), data.Item2, data.Item3 - 1); } else { _typeOfSource = 0; } } else { chatMessagesServer = _serverWorker.GetMessagesStart(); _topID = chatMessagesServer.Count > 0 ? chatMessagesServer[0].Id : -1; _typeOfSource = 0; foreach (var message in chatMessagesServer) { Messages.Add(new Message { Id = message.Id, SenderName = message.SenderName, DateSend = message.DateSend, SendMessage = message.SendMessage, IsItMe = message.SenderName == Name }); AddNewMessageInContainerAndUpdateDateSend(); } } }