private async Task GetComment(int Qusitonid, int Userid) { HttpClient httpClient = new HttpClient { BaseAddress = new Uri("http://localhost:60671/") }; httpClient.DefaultRequestHeaders.Clear(); httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); string str = $"api/comment/getcomment/{Userid}/{Qusitonid}"; HttpResponseMessage httpResponseMessage = await httpClient.GetAsync(str); if (httpResponseMessage.IsSuccessStatusCode) { var res = await httpResponseMessage.Content.ReadAsAsync <string>(); if (res != string.Empty) { commentPlus = new ObservableCollection <Comment>(JsonConvert.DeserializeObject <List <Comment> >(res)); CmtList.ItemsSource = commentPlus; this.Bindings.Update(); foreach (var item in commentPlus) { if (NameMap.UPAnswerCmt.Contains($"{item.Qusitionid} {item.Userid} {item.CmtTime} {Myid} {item.CmdUserid} {item.CmtedUserid}")) { var container = (ListViewItem)CmtList.ContainerFromItem(item); if (container == null) { CmtList.UpdateLayout(); CmtList.ScrollIntoView(CmtList.Items[commentPlus.IndexOf(item)]); container = (ListViewItem)CmtList.ContainerFromItem(item); } var ups = (container.ContentTemplateRoot as FrameworkElement)?.FindName("LikeButton") as AppBarButton; ups.Foreground = new SolidColorBrush(Colors.Blue); } if (NameMap.DNAnswerCmt.Contains($"{item.Qusitionid} {item.Userid} {item.CmtTime} {Myid} {item.CmdUserid} {item.CmtedUserid}")) { var container = (ListViewItem)CmtList.ContainerFromIndex(commentPlus.IndexOf(item)); if (container == null) { CmtList.UpdateLayout(); CmtList.ScrollIntoView(CmtList.Items[commentPlus.IndexOf(item)]); container = (ListViewItem)CmtList.ContainerFromItem(item); } var downs = (container.ContentTemplateRoot as FrameworkElement)?.FindName("DislikeButton") as AppBarButton; downs.Foreground = new SolidColorBrush(Colors.Blue); } } } } }
/// <summary> /// 列表中的某一项被点击 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CmtList_ItemClick(object sender, ItemClickEventArgs e) { foreach (var item in CmtList.Items) { var container = (ListViewItem)CmtList.ContainerFromItem(item); if (container != null) { if ((container.ContentTemplateRoot as FrameworkElement)?.FindName("CmtContenttwo") is FrameworkElement submenu) { if ((container.ContentTemplateRoot as FrameworkElement)?.FindName("CmtContentone") is FrameworkElement submenus) { submenus.Visibility = e.ClickedItem == item ? Visibility.Collapsed : Visibility.Visible; } submenu.Visibility = e.ClickedItem == item ? Visibility.Visible : Visibility.Collapsed; } } } }