public bool AddOrRemove(Comment c) { bool remove = false; foreach (Comment cs in Comments) { if (cs.id == c.id) { Comments.Remove(cs); remove = true; break; } } if (remove == false) { Comments.Add(c); } if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("Comments")); } return !remove; }
public Comment(XElement x, int thisstoryid) { reply_count = (int)x.Attribute("reply_count"); date = ((string)x.Attribute("date")).Substring(0,19); id = (int)x.Attribute("id"); author = (string)x.Attribute("author"); body = StripHTML(((string)x.Element("body")).Trim()); category = (PostCategory)Enum.Parse(typeof(PostCategory), ((string)x.Attribute("category")).Trim(), true); preview = ((string)x.Attribute("preview")).Trim(); storyid = thisstoryid; List<XElement> comments = x.Element("comments").Elements("comment").ToList(); Comments = new ObservableCollection<Comment>(); if (comments.Count() > 0) { foreach (XElement xchild in comments) { Comment child = new Comment(xchild, thisstoryid); Comments.Add(child); } } }
public NestedListBoxItem GetChild(Comment c) { NestedListBox List = GetTemplateChild("List") as NestedListBox; NestedListBoxItem item = (NestedListBoxItem)(List.ItemContainerGenerator.ContainerFromItem(c)); if (item != null) { return item; } else { for (int i = 0; i < List.Items.Count; i++) { item = (NestedListBoxItem)(List.ItemContainerGenerator.ContainerFromIndex(i)); item = item.GetChild(c); if (item != null) { return item; } } } return null; }
protected void UpdateViewer(object sender, EventArgs e) { bool found = false; Comment c = _c; NestedListBoxItem item = (NestedListBoxItem)(CommentsList.ItemContainerGenerator.ContainerFromItem(c)); if (item != null) { item.NestedListBoxItem_Click(null, new RoutedEventArgs()); } else { for (int i = 0; i < CommentsList.Items.Count; i++) { item = (NestedListBoxItem)(CommentsList.ItemContainerGenerator.ContainerFromIndex(i)); item = item.GetChild(c); if (item != null) { found = true; break; } } } if (found) { item.NestedListBoxItem_Click(null, new RoutedEventArgs()); } CompositionTarget.Rendering -= UpdateViewer; _c = null; }
public void SelectedCommentChanged(Comment newSelection) { ShowComment(newSelection); }
void ThreadCreated(object sender, System.ComponentModel.PropertyChangedEventArgs e) { try { _thread.PropertyChanged -= ThreadCreated; _c = _thread.GetComment(_comment); ShowComment(_c); ProgressBar.Visibility = Visibility.Collapsed; CompositionTarget.Rendering += UpdateViewer; } catch(Exception) { } }
private void ShowComment(Comment c) { _comment = c.id; CommentHeader.DataContext = c; CommentViewer.NavigateToString(CoreServices.Instance.AddCommentHTML(c.body)); if (CoreServices.Instance.IsOnWatchedList(c)) { _PinButton.IconUri = new Uri("/Images/sticky_notes.png", UriKind.Relative); _PinButton.Text = "Unpin Thread"; } else { _PinButton.IconUri = new Uri("/Images/PinIcon.png", UriKind.Relative); _PinButton.Text = "Pin Thread"; } shouldStartWebBrowser = true; }
// When page is navigated to set data context to selected item in list protected override void OnNavigatedTo(NavigationEventArgs e) { string sStory = ""; if (NavigationContext.QueryString.TryGetValue("Story", out sStory)) { _story = int.Parse(sStory); } else { NavigationService.GoBack(); } if (CoreServices.Instance.ReplyToContext != null) { _reply = CoreServices.Instance.ReplyToContext; DataContext = _reply; } else { CommentReplyBox.Visibility = Visibility.Collapsed; } if (CoreServices.Instance.LoginVerified == false) { Login.Visibility = Visibility.Visible; } }
public bool IsOnWatchedList(Comment c) { return WatchList.IsOnWatchList(c); }
public bool AddOrRemoveWatch(Comment c) { return WatchList.AddOrRemove(c); }
public bool IsOnWatchList(Comment c) { foreach (Comment cs in Comments) { if (cs.id == c.id) { return true; } } return false; }
public void Add(Comment c) { Comments.Add(c); }
public void Remove(Comment c) { Comments.Remove(c); }