private void MessageListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.MessageListBox.SelectedIndex != -1) { var dialog = new EditMessageDialog(); MessageUiForm tmp_msg = (this.MessageListBox.Items[this.MessageListBox.SelectedIndex] as MessageUiForm); dialog.MsgTextBox.Text = tmp_msg.MessageText; dialog.MsgDatePicker.SelectedDate = DateTime.Parse(tmp_msg.SendDateTime); dialog.MsgTimePicker.SelectedTime = DateTime.Parse(tmp_msg.SendDateTime); dialog.MessageContentUrl = tmp_msg.MessageContentUrl; dialog.MyTurnToggle.IsChecked = tmp_msg.MyTurn; dialog.ShowDialog(); if (dialog.DoesExecuted) { var new_msg = new Message() { MyTurn = (bool)dialog.MyTurnToggle.IsChecked, MessageText = dialog.MsgTextBox.Text, SendDateTime = DateTime.Parse(dialog.MsgDatePicker.SelectedDate.ToString()).ToShortDateString() + " " + DateTime.Parse(dialog.MsgTimePicker.SelectedTime.ToString()).ToLongTimeString(), SenderName = this.ChatTopName_TextBlock.Text, MessageContentUrl = dialog.MessageContentUrl }; XmlFunctions.WriteDayJournal(new_msg, CurrentChatID, (this.MessageListBox.Items[this.MessageListBox.SelectedIndex] as MessageUiForm).SendDateTime); ClearCurrentDialog(); LoadChatFromPrev(GetCurrentChatButtonInstance(), new RoutedEventArgs()); } } }
private void SendMsgBtn_Click(object sender, RoutedEventArgs e) { if (this.MyMsg.Text != "") {//НЕ ПУСТОЕ СООБЩЕНИЕ var msg = new MessageUiForm(this.MyMsg.Text.Trim(), DateTime.Now.ToString(), this.ChatTopName_TextBlock.Text); this.MessageListBox.Items.Add(msg); MoveChatScrollToDownEnd(); UpdatePreviewFull(); XmlFunctions.UpdateDayJournal(msg, CurrentChatID); this.MyMsg.Text = ""; SortPrevsByDate(); //List<MessageUiForm> listMsg = new List<MessageUiForm>(); //foreach (var item in this.MessageListBox.Items) { // listMsg.Add(item as MessageUiForm); //} //listMsg.Sort() //this.MessageListBox.Items.Clear(); //foreach (var item in this.MessageListBox.Items) // this.MessageListBox.Items.Add(item); } }
private void ChatScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e) { if (this.ChatGrid.RowDefinitions[0].Height != new GridLength(0)) { if (this.ChatScrollViewer.VerticalOffset == 0 /*&& this.ChatScrollViewer.ScrollableHeight != 0*/) { if (ChatScrollViewerVerticalOffsetZeroPointerFixer) { DayMessageJournalSerializable s = XmlFunctions.GetDayJournal(CurrentChatID, LoadPrevLastChatFile()); if (s != null) { int index = 0; foreach (var item in s.Messages) { var tmp_msg = new MessageUiForm(item.MessageText, item.SendDateTime, item.SenderName, item.DoesRead, item.DoesRead, item.MessageContentUrl) { DoesRead = item.DoesRead, MessageContentUrl = item.MessageContentUrl, MyTurn = item.MyTurn, SenderName = item.SenderName, SendDateTime = item.SendDateTime }; bool test_first_msg = false; foreach (var i in this.MessageListBox.Items) { if ((i as MessageUiForm).SendDateTime == tmp_msg.SendDateTime) { test_first_msg = true; } } if (!test_first_msg) { MessageListBox.Items.Insert(index, tmp_msg); // MessageBox.Show($"{tmp_msg.MessageText}"); } index++; } this.ChatScrollViewer.LineDown(); this.ChatScrollViewer.LineDown(); this.ChatScrollViewer.LineDown(); this.ChatScrollViewer.LineDown(); this.ChatScrollViewer.LineDown(); //MessageBox.Show(this.ChatScrollViewer.VerticalOffset.ToString()); GC.Collect(); ChatScrollViewerVerticalOffsetZeroPointerFixer = false; } //MessageBox.Show(CurrentLoadedDate.ToString()); } else { ChatScrollViewerVerticalOffsetZeroPointerFixer = true; } } } }
private void SendMsgBtnToMe_Click(object sender, RoutedEventArgs e) { if (this.MyMsg.Text != "") {//НЕ ПУСТОЕ СООБЩЕНИЕ var msg = new MessageUiForm(this.MyMsg.Text.Trim(), DateTime.Now.ToString(), this.ChatTopName_TextBlock.Text, false); this.MessageListBox.Items.Add(msg); MoveChatScrollToDownEnd(); UpdatePreviewFull(); XmlFunctions.UpdateDayJournal(msg, CurrentChatID); this.MyMsg.Text = ""; SortPrevsByDate(); } }
private void SendImgMsgBtn_Click(object sender, RoutedEventArgs e) { string CurrentPathToPict = ""; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Image Files|*.jpg; *.jpeg; *.png"; if (openFileDialog.ShowDialog() == true) { CurrentPathToPict = openFileDialog.FileName; } Directory.CreateDirectory(Properties.Resources.UserDataDirPath + "\\" + CurrentChatID); if ((!File.Exists(Properties.Resources.UserDataDirPath + "\\" + CurrentChatID + "\\" + System.IO.Path.GetFileName(openFileDialog.FileName)) && File.Exists(openFileDialog.FileName))) { string destionation = Properties.Resources.UserDataDirPath + "\\" + CurrentChatID + "\\" + System.IO.Path.GetFileName(openFileDialog.FileName); File.Copy(openFileDialog.FileName, destionation); #region MessageInUi var msg = new MessageUiForm("IMAGE_CONTENT", DateTime.Now.ToString(), this.ChatTopName_TextBlock.Text, true, true, destionation); this.MessageListBox.Items.Add(msg); MoveChatScrollToDownEnd(); UpdatePreviewFull(); XmlFunctions.UpdateDayJournal(msg, CurrentChatID); this.MyMsg.Text = ""; SortPrevsByDate(); #endregion MessageInUi } }