Beispiel #1
0
        private static void OnMsessageStatePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ChatImage target = d as ChatImage;

            switch (target.State)
            {
            case MessageStates.Fail:
                if (target.DataContext is MessageModel msg && msg.IsMine)
                {
                    target.pathResend.Visibility = Visibility.Visible;
                }
                else
                {
                    target.gridFail.Visibility = Visibility.Visible;
                }
                target.aniLoading.Stop();
                target.gridLayout.Children.Remove(target.aniLoading);
                break;
Beispiel #2
0
 public void AddImageItem(string imgPath)
 {
     if (GetImageCount() < 10)
     {
         if (File.Exists(imgPath))
         {
             FileInfo fileInfo = new FileInfo(imgPath);
             if (fileInfo.Length < 50 * 1024 * 1024)
             {
                 ChatImage img = new ChatImage(imgPath, new Size(320, 180))
                 {
                     Uid = ViewModels.AppData.FlagImage + imgPath
                 };
                 this.AddUI(img);
             }
             else
             {
                 ViewModels.AppData.MainMV.TipMessage = "图片超过50MG,建议文件形式发送!";
             }
         }
     }
 }
Beispiel #3
0
        private static void OnImagePathPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ChatImage target = d as ChatImage;

            target.LoadImg();
        }
Beispiel #4
0
        private void DoPaste()
        {
            this.richBox.Selection.Text = string.Empty;
            if (Clipboard.ContainsFileDropList())
            {
                var files = Clipboard.GetFileDropList();
                foreach (var f in files)
                {
                    var tension = System.IO.Path.GetExtension(f).ToLower();
                    if (ImageFilter.Contains(tension))
                    {
                        AddImageItem(f);
                    }
                    else
                    {
                        AddFileItems(new string[] { f });
                    }
                }
            }
            else if (Clipboard.ContainsImage())
            {
                BitmapSource bitmap  = Clipboard.GetImage();
                string       imgPath = Helper.ImageDeal.SaveBitmapImageIntoFile(bitmap);

                AddImageItem(imgPath);
                //内存同样图片,已经创建一次,直接赋值给文件形式
                //Clipboard.SetData(ViewModels.AppData.FlagCopy, new List<string> { ViewModels.AppData.FlagImage + imgPath });
            }
            else
            {
                var formats = Clipboard.GetDataObject().GetFormats();
                if (formats.Contains(DataFormats.Rtf))
                {
                    #region Load rtf content
                    var rtf = Clipboard.GetData(DataFormats.Rtf);
                    //将rtf载入内存内的RichTextBox
                    using (MemoryStream rtfMemoryStream = new MemoryStream())
                    {
                        using (StreamWriter rtfStreamWriter = new StreamWriter(rtfMemoryStream))
                        {
                            rtfStreamWriter.Write(rtf);
                            rtfStreamWriter.Flush();
                            rtfMemoryStream.Seek(0, SeekOrigin.Begin);
                            //Load the MemoryStream into TextRange ranging from start to end of RichTextBox.
                            this.richBox.Selection.Load(rtfMemoryStream, DataFormats.Rtf);
                        }
                    }

                    var datas = Helper.RichTextBoxHelper.GetSelectionItems(this.richBox);
                    this.richBox.Selection.Text = string.Empty;
                    var tp = this.richBox.CaretPosition;
                    for (int i = 0; i < datas.Count; i++)
                    {
                        if (datas[i] is Run run)
                        {
                            run = new Run(run.Text, tp);
                            tp  = run.ContentEnd;
                        }

                        else if (datas[i] is InlineUIContainer uic)
                        {
                            if (uic.Child is Image img)
                            {
                                string path = img.Source.ToString();
                                if (File.Exists(path))
                                {
                                }
                                else if (img.Source is BitmapSource bitSource)
                                {
                                    path = Helper.ImageDeal.SaveBitmapImageIntoFile(bitSource);
                                }
                                else
                                {
                                    continue;
                                }

                                ChatImage chatImg = new ChatImage(path, new Size(320, 180))
                                {
                                    Uid = ViewModels.AppData.FlagImage + path
                                };

                                uic = new InlineUIContainer(chatImg, tp);
                                tp  = uic.ContentEnd;
                            }
                            else
                            {
                                uic.Child.ToString();
                            }
                        }
                        else
                        {
                            //var vv = datas[i].ToString();
                            //vv.ToString();
                        }
                    }

                    #endregion
                }
                else if (formats.Contains(CSClient.ViewModels.AppData.FlagCopy))
                {
                    string textCopy = Clipboard.GetData(CSClient.ViewModels.AppData.FlagCopy).ToString();
                    CSClient.Helper.MessageHelper.AppendContentToRichTextBox(this.richBox, textCopy);
                }
                else if (formats.Contains(DataFormats.Html))
                {
                    string html = Clipboard.GetData(DataFormats.Html).ToString();
                    CSClient.Helper.MessageHelper.AppendHtmlFromClipboard(this.richBox, html);
                }
                else
                {
                    CSClient.Helper.MessageHelper.AppendContentToRichTextBox(this.richBox, Clipboard.GetText());
                }
            }
        }