Exemplo n.º 1
0
        private async void TextBox3_Paste(object sender, TextControlPasteEventArgs e)
        {
            await new MessageDialog("禁用粘贴").ShowAsync();

            // 将路由事件设置为已处理,从而禁用粘贴功能
            e.Handled = true;
        }
Exemplo n.º 2
0
        private async void Set_ClipboardNoUI(object sender, TextControlPasteEventArgs e)
        {
            // Mark the event as handled first. Otherwise, the
            // default paste action will happen, then the custom paste
            // action, and the user will see the text box content change.
            e.Handled = true;

            // Get content from the clipboard.
            var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();

            if (dataPackageView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.Text))
            {
                string outputStr = "";

                var policyResult = dataPackageView.UnlockAndAssumeEnterpriseIdentity();
                if (policyResult != ProtectionPolicyEvaluationResult.Allowed)
                {
                    outputStr += "Policy does not allow accessing clipboard";
                }
                var text = await dataPackageView.GetTextAsync();

                var txtBox = sender as TextBox;
                txtBox.Text = text;
                outputStr  += text != null ? "Successfully pasted" : "Pasting text failed";
                rootPage.NotifyUser(outputStr, NotifyType.StatusMessage);
            }
        }
        //用户粘贴URL到TextBox,粘贴失败会播放音效
        private async void TextBox_UrlInput_Paste(object sender, TextControlPasteEventArgs e)
        {
            //AlbumCollection.Add(new Album(e.ToString));
            if (EnablePaste)
            {
                var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
                if (dataPackageView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.Text))
                {
                    try
                    {
                        var text = await dataPackageView.GetTextAsync();

                        AlbumCollection.Add(new Album(text));
                    }
                    catch
                    {
                        var player = new MediaPlayer();
                        player.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Sounds/Windows_1.wav"));
                        player.Play();
                    }
                }

                TextBox textbox = sender as TextBox;
                textbox.Text = string.Empty;
            }
        }
Exemplo n.º 4
0
 //粘贴事件
 private void TextBox1_Paste(object sender, TextControlPasteEventArgs e)
 { 
     text =TextBox1.Text;
     selectedText =TextBox1.SelectedText;
     pasteTest ="产生了粘贴操作";
     ShowInformation();
 }
Exemplo n.º 5
0
        private async void OnPaste(object sender, TextControlPasteEventArgs e)
        {
            // If the user tries to paste RTF content from any TOM control (Visual Studio, Word, Wordpad, browsers)
            // we have to handle the pasting operation manually to allow plaintext only.
            var package = Clipboard.GetContent();

            if (package.Contains(StandardDataFormats.Text) && package.Contains("Rich Text Format"))
            {
                e.Handled = true;

                var formats = package.AvailableFormats.ToList();
                var text    = await package.GetTextAsync();

                var result = Emoticon.Pattern.Replace(text, (match) =>
                {
                    var emoticon = match.Groups[1].Value;
                    var emoji    = Emoticon.Replace(emoticon);
                    if (match.Value.StartsWith(" "))
                    {
                        emoji = $" {emoji}";
                    }

                    return(emoji);
                });

                Document.Selection.SetText(TextSetOptions.None, result);
            }
            else if (package.Contains(StandardDataFormats.StorageItems))
            {
                e.Handled = true;
            }
            else if (package.Contains(StandardDataFormats.Bitmap))
            {
                e.Handled = true;

                var bitmap = await package.GetBitmapAsync();

                var cache = await ApplicationData.Current.LocalFolder.CreateFileAsync("temp\\paste.jpg", CreationCollisionOption.ReplaceExisting);

                using (var stream = await bitmap.OpenReadAsync())
                    using (var reader = new DataReader(stream))
                    {
                        await reader.LoadAsync((uint)stream.Size);

                        var buffer = new byte[(int)stream.Size];
                        reader.ReadBytes(buffer);
                        await FileIO.WriteBytesAsync(cache, buffer);
                    }

                ViewModel.SendPhotoCommand.Execute(new StoragePhoto(cache));
            }
            else if (package.Contains(StandardDataFormats.Text) && package.Contains("application/x-tl-field-tags"))
            {
                // This is our field format
            }
            else if (package.Contains(StandardDataFormats.Text) && package.Contains("application/x-td-field-tags"))
            {
                // This is Telegram Desktop mentions format
            }
        }
        private async void Set_ClipboardNoUI(object sender, TextControlPasteEventArgs e)
        {
            // Mark the event as handled first. Otherwise, the
            // default paste action will happen, then the custom paste
            // action, and the user will see the text box content change.
            e.Handled = true;

            // Get content from the clipboard.
            var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
            if (dataPackageView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.Text))
            {
                string outputStr = "";

                var policyResult = dataPackageView.UnlockAndAssumeEnterpriseIdentity();
                if (policyResult != ProtectionPolicyEvaluationResult.Allowed)
                {
                    outputStr += "Policy does not allow accessing clipboard";
                }
                var text = await dataPackageView.GetTextAsync();
                var txtBox = sender as TextBox;
                txtBox.Text = text;
                outputStr += text != null ? "Successfully pasted" : "Pasting text failed";
                rootPage.NotifyUser(outputStr, NotifyType.StatusMessage);
            }
        }
Exemplo n.º 7
0
        private async void Address_Paste(object sender, TextControlPasteEventArgs e)
        {
            var textBox = sender as TextBox;

            if (!string.IsNullOrWhiteSpace(textBox.Text))
            {
                return;
            }

            e.Handled = true;

            var clipboard = Clipboard.GetContent();

            if (clipboard.Contains(StandardDataFormats.Text))
            {
                var text = await clipboard.GetTextAsync();

                if (ViewModel.TryParseUrl(text))
                {
                    return;
                }

                textBox.Text = text;
            }
        }
Exemplo n.º 8
0
        private async Task IPAdrressTextBox_Paste(object sender, TextControlPasteEventArgs e)
        {
            TextBox tb = (sender as TextBox);

            var dataPackageView = Clipboard.GetContent();

            if (dataPackageView.Contains(StandardDataFormats.Text))
            {
                try
                {
                    // get text from clipboard
                    var text = await dataPackageView.GetTextAsync();

                    // use this regular expression to validate IP format
                    Regex nonNumericRegex = new Regex(@"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b");
                    if (!nonNumericRegex.IsMatch(text))
                    {
                        // no match, show error!
                        ShowInvalidAddressFormatErrorMsg(tb.Name);
                    }
                    else
                    {
                        // we have a match, hide error message in case it was shown
                        HideInvalidAddressFormatErrorMsg(tb.Name);
                    }
                }
                catch
                {
                }
            }
            // update button is enabled state
            UpdateIsEnabledButtonState();
        }
        private async void PasteButton_Click(object sender, TextControlPasteEventArgs e)
        {
            // Mark the event as handled first. Otherwise, the
            // default paste action will happen, then the custom paste
            // action, and the user will see the text box content change.
            e.Handled = true;

            // Get content from the clipboard.
            var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
            if (dataPackageView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.Text))
            {
                var response = await dataPackageView.RequestAccessAsync();
                if (response == ProtectionPolicyEvaluationResult.Allowed)
                {
                    (sender as TextBox).Text = await dataPackageView.GetTextAsync();
                    string sourceId = dataPackageView.Properties.EnterpriseId != null ? dataPackageView.Properties.EnterpriseId : "<Personal>";
                    string targetId = ProtectionPolicyManager.GetForCurrentView().Identity != null ? dataPackageView.Properties.EnterpriseId : "<Personal>";
                    string message = "Successfully pasted text from EnterpriseId " + sourceId + " to EnterpriseId " + targetId;
                    rootPage.NotifyUser(message, NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser("User or policy blocked access", NotifyType.StatusMessage);
                }
            }
        }
Exemplo n.º 10
0
        private async void RichEditBox_Paste(object sender, TextControlPasteEventArgs e)
        {
            if (Images.Count >= 9)
            {
                return;
            }
            var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();

            if (dataPackageView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.Bitmap))
            {
                e.Handled = true;
                var bitmap = await dataPackageView.GetBitmapAsync();

                var file = await GetFileFromBitmap(bitmap);
                await AddImageDataFromFile(file, true);
            }
            else if (dataPackageView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.StorageItems))
            {
                e.Handled = true;
                var files = (await dataPackageView.GetStorageItemsAsync()).Where(item => item is StorageFile && (item as StorageFile).ContentType.Contains("image")).ToList();
                if (AllowMorePicture)
                {
                    for (int i = 0; i < 9 && i < files.Count; i++)
                    {
                        await AddImageDataFromFile(files[i] as StorageFile);
                    }
                }
                else
                {
                    await AddImageDataFromFile(files[0] as StorageFile);
                }
            }
        }
Exemplo n.º 11
0
        private static async void Textbox_Paste(object sender, TextControlPasteEventArgs e)
        {
            e.Handled = true;
            DataPackageView dataPackageView = Clipboard.GetContent();

            if (!dataPackageView.Contains(StandardDataFormats.Text))
            {
                return;
            }

            var pasteText = await dataPackageView.GetTextAsync();

            if (string.IsNullOrWhiteSpace(pasteText))
            {
                return;
            }

            var textbox = (TextBox)sender;
            var mask    = textbox.GetValue(MaskProperty) as string;
            var representationDictionary = textbox?.GetValue(RepresentationDictionaryProperty) as Dictionary <char, string>;
            var placeHolderValue         = textbox.GetValue(PlaceHolderProperty) as string;

            if (string.IsNullOrWhiteSpace(mask) ||
                representationDictionary == null ||
                string.IsNullOrEmpty(placeHolderValue))
            {
                return;
            }

            // to update the textbox text without triggering TextChanging text
            textbox.TextChanging -= Textbox_TextChanging;
            SetTextBoxValue(pasteText, textbox, mask, representationDictionary, placeHolderValue[0]);
            textbox.SetValue(OldTextProperty, textbox.Text);
            textbox.TextChanging += Textbox_TextChanging;
        }
Exemplo n.º 12
0
        private async void OnRichEditBoxPaste(object sender, TextControlPasteEventArgs e)
        {
            try
            {
                DataPackageView dataPackageView = Clipboard.GetContent();
                string          text            = null;
                string          html            = null;

                if (dataPackageView.Contains(StandardDataFormats.Text))
                {
                    text = await dataPackageView.GetTextAsync();
                }

                if (dataPackageView.Contains(StandardDataFormats.Html))
                {
                    html = await dataPackageView.GetHtmlFormatAsync();
                }

                // lots of hack, but basically, it's just for OneNote...
                if (this.rtbNotes.Document.Selection != null && html != null && html.Contains("Version:1.0") && !html.Contains("SourceURL") && html.Contains("<meta name=Generator content=\"Microsoft OneNote"))
                {
                    this.rtbNotes.Document.Selection.TypeText(text);
                    e.Handled = true;
                }
            }
            catch (Exception ex)
            {
                TrackingManagerHelper.Exception(ex, "Exception while pasting data: " + ex);
                e.Handled = false;
            }
        }
Exemplo n.º 13
0
        private async void PasteButton_Click(object sender, TextControlPasteEventArgs e)
        {
            // Mark the event as handled first. Otherwise, the
            // default paste action will happen, then the custom paste
            // action, and the user will see the text box content change.
            e.Handled = true;

            // Get content from the clipboard.
            var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();

            if (dataPackageView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.Text))
            {
                var response = await dataPackageView.RequestAccessAsync();

                if (response == ProtectionPolicyEvaluationResult.Allowed)
                {
                    (sender as TextBox).Text = await dataPackageView.GetTextAsync();

                    string sourceId = dataPackageView.Properties.EnterpriseId != null ? dataPackageView.Properties.EnterpriseId : "<Personal>";
                    string targetId = ProtectionPolicyManager.GetForCurrentView().Identity != null ? dataPackageView.Properties.EnterpriseId : "<Personal>";
                    string message  = "Successfully pasted text from EnterpriseId " + sourceId + " to EnterpriseId " + targetId;
                    rootPage.NotifyUser(message, NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser("User or policy blocked access", NotifyType.StatusMessage);
                }
            }
        }
Exemplo n.º 14
0
 //粘贴事件
 private void TextBox1_Paste(object sender, TextControlPasteEventArgs e)
 {
     text         = TextBox1.Text;
     selectedText = TextBox1.SelectedText;
     pasteTest    = "产生了粘贴操作";
     ShowInformation();
 }
Exemplo n.º 15
0
 private void MajorTextBox_Paste(object sender, TextControlPasteEventArgs e)
 {
     if (!IsTextAllowed(MajorTextBox.Text))
     {
         e.Handled = true;
     }
 }
Exemplo n.º 16
0
        public async Task PastePlainTextFromWindowsClipboard(TextControlPasteEventArgs e)
        {
            if (e != null)
            {
                e.Handled = true;
            }

            if (!Document.CanPaste())
            {
                return;
            }

            var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();

            if (!dataPackageView.Contains(StandardDataFormats.Text))
            {
                return;
            }
            try
            {
                var text = await dataPackageView.GetTextAsync();

                text = GetTextWithDefaultTabIndentation(text);
                Document.Selection.SetText(TextSetOptions.None, text);
                Document.Selection.StartPosition = Document.Selection.EndPosition;
            }
            catch (Exception)
            {
                // ignore
            }
        }
Exemplo n.º 17
0
        private async void TextBlock1_Paste(object sender, TextControlPasteEventArgs e)
        {
            TextBox TextBlock1 = sender as TextBox;

            if (TextBlock1 != null)
            {
                e.Handled = true;

                var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
                if (dataPackageView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.Text))
                {
                    try
                    {
                        var text = await dataPackageView.GetTextAsync();

                        string singleLineText = text;

                        TextBlock1.Text = singleLineText;
                    }

                    catch (Exception)
                    {
                        // nada
                    }
                }
            }
        }
Exemplo n.º 18
0
        private async void TextBox_OnPaste(object sender, TextControlPasteEventArgs e) {
            DataPackageView content = Clipboard.GetContent();
            List<string> formats = content.AvailableFormats.ToList();
            if (!formats.Contains(StandardDataFormats.Bitmap))
                return;

            RandomAccessStreamReference bitmap = await Clipboard.GetContent().GetBitmapAsync();
            await ViewModel.AttachPastedFile(await BitmapToPng(bitmap));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Put each digit of the MFA code from the clipboard to the corresponding place
        /// </summary>
        /// <param name="sender"><see cref="TextBox"/> that sent the paste event</param>
        /// <param name="e">Event arguments</param>
        private async void OnInputTextBoxPaste(object sender, TextControlPasteEventArgs e)
        {
            TextBox tb = sender as TextBox;

            if (tb == null)
            {
                return;
            }

            // Mark the event as handled first. Otherwise, the
            // default paste action will happen, then the custom paste
            // action, and the user will see the text box content change.
            e.Handled = true;

            try
            {
                // Get content from the clipboard.
                var dataPackageView = Clipboard.GetContent();
                if (!dataPackageView.Contains(StandardDataFormats.Text))
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_WARNING, "Invalid MFA code. Format is not correct");
                    DialogService.SetMultiFactorAuthCodeInputDialogWarningMessage();
                    return;
                }

                // Check if the code format is correct
                var text = await dataPackageView.GetTextAsync();

                if (string.IsNullOrWhiteSpace(text) || !ValidationService.IsDigitsOnly(text))
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_WARNING, "Invalid MFA code. Format is not correct");
                    DialogService.SetMultiFactorAuthCodeInputDialogWarningMessage();
                    return;
                }

                // Check if the code length is correct
                if (text.Length != this.ViewModel.Settings.MinLength)
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_WARNING, "Invalid MFA code. Length is not correct");
                    DialogService.SetMultiFactorAuthCodeInputDialogWarningMessage();
                    return;
                }

                this.ViewModel.Digit1 = text[0].ToString();
                this.ViewModel.Digit2 = text[1].ToString();
                this.ViewModel.Digit3 = text[2].ToString();
                this.ViewModel.Digit4 = text[3].ToString();
                this.ViewModel.Digit5 = text[4].ToString();
                this.ViewModel.Digit6 = text[5].ToString();
            }
            catch (Exception ex)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Error pasting MFA code", ex);
                DialogService.SetMultiFactorAuthCodeInputDialogWarningMessage();
            }
        }
Exemplo n.º 20
0
        private async void Brainf_ckEditBox_Paste(object sender, TextControlPasteEventArgs e)
        {
            e.Handled = true;

            // Insert the text if there is some available
            if (await ClipboardHelper.TryGetTextAsync() is string text)
            {
                InsertText(text);
            }
        }
Exemplo n.º 21
0
 private void AssociatedObject_Paste(object sender, TextControlPasteEventArgs e)
 {
     if (_clipboarText != null)
     {
         var newText = GetNewText(_clipboarText);
         var ci      = GetCultureInfo();
         if (!double.TryParse(newText, this.NumberStyles, ci, out var v))
         {
             e.Handled = true;
         }
     }
 }
Exemplo n.º 22
0
        public async void clipboard(TextControlPasteEventArgs e)
        {
            if (writetext)
            {
                return;
            }

            e.Handled = true;
            DataPackageView con = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
            string          str = await _m.clipboard(con);

            tianjia(str);
        }
Exemplo n.º 23
0
        private void MessageEditor_Paste(object sender, TextControlPasteEventArgs e)
        {
            e.Handled = false;
            DataPackageView dataPackageView = Clipboard.GetContent();

            if (dataPackageView.Contains(StandardDataFormats.Bitmap) || dataPackageView.Contains(StandardDataFormats.StorageItems))
            {
                OpenAdvanced(null, new OpenAdvancedArgs()
                {
                    Paste = true
                });
            }
        }
        private async void Set_ClipboardNoUI(object sender, TextControlPasteEventArgs e)
        {
            TextBox txtBox    = sender as TextBox;
            string  outputStr = "";

            try
            {
                if (txtBox != null)
                {
                    // Mark the event as handled first. Otherwise, the
                    // default paste action will happen, then the custom paste
                    // action, and the user will see the text box content change.
                    e.Handled = true;

                    // Get content from the clipboard.
                    var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
                    if (dataPackageView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.Text))
                    {
                        //  ProtectionPolicyResult policyResult = await dataPackageView.UnlockAndAssumeIdentity();
                        // if (policyResult != ProtectionPolicyResult.Allowed)
                        //  {
                        //     outputStr += "Can access clipboard";
                        // }
                        // else
                        //  {
                        //await dataPackageView.RequestAccessAsync();
                        // }
                        var text = await dataPackageView.GetTextAsync();

                        txtBox.Text = text;
                        if (text != null)
                        {
                            outputStr = "Successfully pasted text";
                        }
                        else
                        {
                            outputStr = "Pasting text failed";
                        }

                        rootPage.NotifyUser(outputStr, NotifyType.StatusMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                rootPage.NotifyUser(ex.ToString(), NotifyType.ErrorMessage);
            }
        }
        private void TextBox_Paste(object sender, TextControlPasteEventArgs e)
        {
            if (Text.Length == 0)
            {
                return;
            }

            double result;

            if (double.TryParse(Text, out result))
            {
                return;
            }

            Text = "";
        }
Exemplo n.º 26
0
        private async void TextBox_Clipboard(object sender, TextControlPasteEventArgs e)
        {
            DataPackageView data = Clipboard.GetContent();

            if (data != null)
            {
                if (data.Contains(StandardDataFormats.Bitmap))
                {
                    await SetClipimage(data);
                }
                else if (data.Contains(StandardDataFormats.StorageItems))
                {
                    StorageFile file = (await data.GetStorageItemsAsync()).First() as StorageFile;
                    await ImageStorageFile(file);
                }
            }
        }
Exemplo n.º 27
0
        private async void TextBox_Clipboard(object sender, TextControlPasteEventArgs e)
        {
            DataPackageView data = Clipboard.GetContent();

            if (data != null)
            {
                if (data.Contains(StandardDataFormats.Bitmap))
                {
                    RandomAccessStreamReference file = await data.GetBitmapAsync();

                    BitmapImage image = new BitmapImage();
                    await image.SetSourceAsync(await file.OpenReadAsync());

                    this.image.Source = image;
                    View.Image        = image;
                }
            }
        }
Exemplo n.º 28
0
        private async void PasteFromClipboard(object sender, TextControlPasteEventArgs e)
        {
            DataPackageView dataPackageView = Clipboard.GetContent();

            if (dataPackageView.Contains(StandardDataFormats.StorageItems))
            {
                var param = await dataPackageView.GetStorageItemsAsync();

                foreach (var file in param)
                {
                    AddAttachment(file as StorageFile);
                }
            }
            else if (dataPackageView.Contains(StandardDataFormats.Bitmap))
            {
                string hexValue = string.Empty;

                for (int i = 0; i < 8; i++)
                {
                    int num = random.Next(0, int.MaxValue);
                    hexValue += num.ToString("X8");
                }

                var bmpDPV = await dataPackageView.GetBitmapAsync();

                string fileName = $"{hexValue}.png";
                var    bmpSTR   = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);

                using (var writeStream = (await bmpSTR.OpenStreamForWriteAsync()).AsRandomAccessStream())
                    using (var readStream = await bmpDPV.OpenReadAsync())
                    {
                        BitmapDecoder decoder = await BitmapDecoder.CreateAsync(readStream.CloneStream());

                        BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, writeStream);

                        encoder.SetSoftwareBitmap(await decoder.GetSoftwareBitmapAsync());
                        await encoder.FlushAsync();

                        ViewModel.Attachments.Add(new StreamPart(await bmpSTR.OpenStreamForReadAsync(), fileName, bmpSTR.ContentType));
                    }
            }
        }
Exemplo n.º 29
0
        private async System.Threading.Tasks.Task PasteContentHandler(TextControlPasteEventArgs e)
        {
            var dataPackageView = Clipboard.GetContent();

            if (!dataPackageView.Contains(StandardDataFormats.StorageItems))
            {
                return;
            }

            var pasteContent = await dataPackageView.GetStorageItemsAsync();

            foreach (var content in pasteContent)
            {
                var file = content as StorageFile;
                if (file == null)
                {
                    continue;
                }

                if (file.ContentType.Contains("image"))
                {
                    using (var imageStream = await file.OpenReadAsync())
                    {
                        richEditBox.Document.Selection.InsertImage(50, 50,
                                                                   0, VerticalCharacterAlignment.Baseline, "Image", imageStream);
                    }
                    continue;
                }

                if (file.ContentType.Contains("video") || file.ContentType.Contains("audio"))
                {
                    richEditBox.Document.Selection.SetText(TextSetOptions.None, file.Name);
                    richEditBox.Document.Selection.Move(TextRangeUnit.Word, file.Name.Length);
                }
            }

            string text;

            richEditBox.Document.GetText(TextGetOptions.None, out text);

            e.Handled = true;
        }
Exemplo n.º 30
0
        private async void RichEditBox_Paste(object sender, TextControlPasteEventArgs e)
        {
            Paste?.Invoke(this, e);

            if (e.Handled || TextDocument == null || ClipboardPasteFormat != RichEditClipboardFormat.PlainText)
            {
                return;
            }

            e.Handled = true;
            var dataPackageView = Clipboard.GetContent();

            if (dataPackageView.Contains(StandardDataFormats.Text))
            {
                var text = await dataPackageView.GetTextAsync();

                TextDocument.Selection.SetText(TextSetOptions.Unhide, text);
                TextDocument.Selection.Collapse(false);
            }
        }
Exemplo n.º 31
0
        private async void MessageTextBox_OnPaste(object sender, TextControlPasteEventArgs e)
        {
            var data = Clipboard.GetContent();

            if (data.Contains(StandardDataFormats.Bitmap))
            {
                try
                {
                    var streamReference = await data.GetBitmapAsync();

                    var stream = await streamReference.OpenReadAsync();

                    ((ConversationViewModel)DataContext).AttachPhotoFromStream(stream.CloneStream(), stream.ContentType);
                    stream.Dispose();
                }
                catch { }

                e.Handled = true;
            }
            else if (data.Contains(StandardDataFormats.StorageItems))
            {
                var items = await data.GetStorageItemsAsync();

                foreach (var item in items)
                {
                    try
                    {
                        var file = item as StorageFile;
                        if (file != null && file.ContentType.StartsWith("image/"))
                        {
                            ((ConversationViewModel)DataContext).AttachPhotoFromFile(file);
                        }
                    }
                    catch { }
                }

                e.Handled = true;
            }
        }
Exemplo n.º 32
0
        private async void ContentTextBox_Paste(object sender, TextControlPasteEventArgs e)
        {
            var dpv = Clipboard.GetContent();

            if (dpv.Contains(StandardDataFormats.Bitmap))
            {
                e.Handled = true;
                var cts  = new CancellationTokenSource();
                var file = await dpv.GetBitmapAsync();

                _vm.UploadSingleFile(cts, file, BeforeUpload, AfterUpload);
            }

            if (dpv.Contains(StandardDataFormats.StorageItems))
            {
                e.Handled = true;
                var cts   = new CancellationTokenSource();
                var files = await dpv.GetStorageItemsAsync();

                _vm.UploadMultipleFiles(cts, files, BeforeUpload, AfterUpload);
            }
        }
Exemplo n.º 33
0
        private async void OnPaste(object sender, TextControlPasteEventArgs e)
        {
            var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();

            if (dataPackageView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.Bitmap))
            {
                e.Handled = true;
                var bitmap = await dataPackageView.GetBitmapAsync();

                var file = await bitmap.SaveCacheFile($"Clipboard - {DateTime.Now:yyyy-mm-dd HH-mm-ss}");

                UploadFile?.Invoke(this, file);
            }
            else if (dataPackageView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.StorageItems))
            {
                e.Handled = true;
                var files = (await dataPackageView.GetStorageItemsAsync())
                            .Select(it => it as StorageFile)
                            .ToArray();
                UploadFile?.Invoke(this, files.FirstOrDefault());
            }
        }
Exemplo n.º 34
0
        //来自剪贴板内容的限制
        private void ContentRichEditBox_Paste(object sender, TextControlPasteEventArgs e)
        {
            if (ContentRichEditBox.Document.CanPaste())
            {
                var content = Clipboard.GetContent();

                if (content.Contains("text") || content.Contains("rtf"))
                {
                    //0 代表最佳格式,通常为RTF格式。
                    //1 代表 CF_TEXT
                    //2 代表 CF_BITMAP : A handle to a bitmap
                    //8 代表 CF_DIB : A memory object containing a BITMAPINFO structure followed by the bitmap bits.
                    //具体的FormatId介绍:https://msdn.microsoft.com/en-us/library/windows/desktop/ff729168.aspx?f=255&MSPPError=-2147217396
                    ContentRichEditBox.Document.Selection.Paste(1);
                }
                if (content.Contains("bitmap"))
                {
                    ContentRichEditBox.Document.Selection.SetText(TextSetOptions.None, "bitmap");
                }

                e.Handled = true;
            }
        }
Exemplo n.º 35
0
 private void Text_Paste(object sender, TextControlPasteEventArgs e)
 {
     view.Clipboard(e);
 }
Exemplo n.º 36
0
        public async void Clipboard(TextControlPasteEventArgs e)
        {
            if (Writetext)
            {
                return;
            }

            e.Handled = true;
            DataPackageView con = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();
            string str = await _m.clipboard(con);
            Tianjia(str);
        }
Exemplo n.º 37
0
        /// <summary>
        /// Displays a preview of the image before the image is sent through processing
        /// </summary>
        private async void showURLImage(object sender, TextControlPasteEventArgs e)
        {

            if (string.IsNullOrEmpty(URL.Text) || URL.Text.Equals("Please Enter a URL"))
            {
                //wait for text to be pasted into the TextBlock definded in xaml
                await Task.Delay(100);
            }
            if (string.IsNullOrEmpty(URL.Text) || URL.Text.Equals("Please Enter a URL"))
            {
                URL.Text = "Please enter a URL";
            }
            try
            {
                String input = URL.Text;

                //checks if the URL entered is a direct reference to a .jpeg, .jpg or .png file
                if (input.Contains(".jpeg") || input.Contains(".jpg") || input.Contains(".png"))
                {
                    Uri uri = new Uri(input);
                    BitmapImage bmpImage = new BitmapImage(uri);
                    errorImage.Visibility = Visibility.Collapsed;
                    errorText.Visibility = Visibility.Collapsed;
                    previewImage.Source = bmpImage;
                }
                else
                {
                    throw new Exception("URL was invalid");
                }
            }
            catch
            {
                URL.Text = "The URL entered was invalid";
                errorImage.Visibility = Visibility.Visible;
                errorText.Visibility = Visibility.Visible;
            }

        }
 private void EditTextBox_OnPaste(object sender, TextControlPasteEventArgs e)
 {
     this.EditTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
 }