private void load(object sender, RoutedEventArgs e) { if (e.Handled) { return; } e.Handled = true; MyTreeViewItem item = e.OriginalSource as MyTreeViewItem; if (item.ShowMessageWindow) { MessageViewWindow window = MessageViewWindow.CreateMessageViewWindow(item.MessageType, item.Argument); new Thread(new ThreadStart(() => { this.Dispatcher.Invoke((Action)(() => { window.Show(); })); })).Start(); window.Load(); } item.IsSelected = false; }
public static MessageViewWindow CreateMessageViewWindow( MessageViewType type, Dictionary <string, object> argument) { MessageViewWindow viewWindow = new MessageViewWindow(); viewWindow.messageView.Type = type; viewWindow.messageView.Argument = argument; return(viewWindow); }
public void SetContent(DisplayMessage msg) { this._messageID = msg.ID; this.UsernameTB.Text = msg.User.Userid; this.TimestampTB.Text = string.Format("{0:F}", msg.PostTime.ToLocalTime()); this.Thumbnail.Source = new ImageSourceConverter().ConvertFromString( ThumbnailRetriever.GetThumbnail(msg.User.PortraitUrl) ) as ImageSource; if (msg.Importance == 0) { //set orange background this.MessageTB.Background = new SolidColorBrush(Color.FromRgb(254, 60, 0)); } if (!string.IsNullOrEmpty(msg.RichMessageID)) { this.ShowMoreBtn.Tag = msg.RichMessageID; this.ShowMoreBtn.IsEnabled = true; this.ShowMoreBtn.Visibility = System.Windows.Visibility.Visible; } //create line in rich text box RichtextHelper helper = new RichtextHelper( msg.Group, (sender, args) => { string url = args.Uri.ToString(); Regex r = new Regex(@"topic=.*?(?=&|$)", RegexOptions.IgnoreCase); if (r.IsMatch(url)) { string topicName = r.Match(url).Value; topicName = topicName.Replace("topic=", ""); topicName = topicName.Replace("&", ""); MessageViewWindow window = MessageViewWindow.CreateMessageViewWindow( MessageViewType.Topic, new Dictionary <string, object>() { { "GroupID", msg.Group }, { "TopicName", topicName } }); window.Show(); window.Load(); } else { Process.Start(url); } } ); List <string> useridList = new List <string>(); if (msg.Owner != null && msg.Owner.Length > 0) { useridList.AddRange(msg.Owner); } if (msg.AtUser != null && msg.AtUser.Length > 0) { useridList.AddRange(msg.AtUser); } helper.RelatedUserIDs = useridList; this.MessageTB.Document.Blocks.Remove(this.MessageTB.Document.Blocks.FirstBlock); this.MessageTB.Document.Blocks.Add(helper.ParseText(msg.MessageContent)); }