public ChatPage() { InitializeComponent(); BindingContext = vm = new ChatBotViewModel(); vm.Messages.CollectionChanged += (sender, e) => { Device.BeginInvokeOnMainThread(() => { var target = vm.Messages[vm.Messages.Count - 1]; MessagesList.ScrollTo(target, ScrollToPosition.End, true); }); }; }
public MainPage() { ChatBotViewModel vm; InitializeComponent(); BindingContext = vm = new ChatBotViewModel(); vm.Messages.CollectionChanged += (sender, e) => { var target = vm.Messages[vm.Messages.Count - 1]; MessagesList.ScrollTo(target, ScrollToPosition.End, true); }; }
public Chat() { Title = "Я - " + (string)App.Current.Properties["Username"] + " для " + (string)App.Current.Properties["toUser"]; InitializeComponent(); viewModel = new ChatViewModel(this); this.BindingContext = viewModel; Dictionary <string, string> responseJson = JsonConvert.DeserializeObject <Dictionary <string, string> >((string)App.Current.Properties["Token"]); HttpClient client = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage(); request.RequestUri = new Uri("http://192.168.100.2:3000/Mobile/GetListOfMessagges?jwt=" + responseJson["access_token"] + "&toUser="******"toUser"]); request.Method = HttpMethod.Post; request.Headers.Add("Accept", "application/json"); HttpResponseMessage response = client.SendAsync(request).Result; if (response.StatusCode == HttpStatusCode.OK) { HttpContent jsonRespone = response.Content; Dictionary <string, object> json = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonRespone.ReadAsStringAsync().Result); JArray a = (JArray)json["messages"]; foreach (JObject b in a) { var z = b.ToObject <Dictionary <string, string> >(); MessageData message = new MessageData { Message = z["contect"], User = z["user1Id"] }; viewModel.Messages.Add(message); } ; var v = MessagesList.ItemsSource.Cast <object>().LastOrDefault(); MessagesList.ScrollTo(v, ScrollToPosition.End, true); } ; }
public void ScrollTo() { var v = MessagesList.ItemsSource.Cast <object>().LastOrDefault(); MessagesList.ScrollTo(v, ScrollToPosition.End, true); }