/// <summary> /// Copy selection of byte to clipboard /// </summary> /// <param name="copyChange">Set tu true if you want onclude change in your copy. Set to false to copy directly from source</param> public void CopyToClipboard(CopyPasteMode copypastemode, long selectionStart, long selectionStop, bool copyChange = true) { if (!CanCopy(selectionStart, selectionStop)) { return; } //Variables byte[] buffer = GetCopyData(selectionStart, selectionStop, copyChange); string sBuffer = ""; DataObject da = new DataObject(); switch (copypastemode) { case CopyPasteMode.ASCIIString: sBuffer = ByteConverters.BytesToString(buffer); da.SetText(sBuffer, TextDataFormat.Text); break; case CopyPasteMode.HexaString: sBuffer = ByteConverters.ByteToHex(buffer); da.SetText(sBuffer, TextDataFormat.Text); break; case CopyPasteMode.Byte: throw new NotImplementedException(); } //set memorystream (BinaryData) clipboard data System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer, 0, buffer.Length, false, true); da.SetData("BinaryData", ms); Clipboard.SetDataObject(da, true); DataCopiedToClipboard?.Invoke(this, new EventArgs()); }
public ClipboardService() { Clipboard.ContentChanged += async(s, e) => { DataPackageView dataPackageView = Clipboard.GetContent(); if (dataPackageView.Contains(StandardDataFormats.Text)) { string text = await dataPackageView.GetTextAsync(); if (text != App.IncomingCopiedText) { DataCopiedToClipboard?.Invoke( this, new SharedDataInfo() { Account = new AccountInfo() { SID = App.User.SID }, SharedText = text }); } } }; }