none
WPF richtextbox 粘贴时如何清除格式 以及屏蔽图片 RRS feed

  • 问题

  • 大家好!,我遇到了一个问题,WPF richtextbox  粘贴时如何清除格式 以及屏蔽图片,

    <RichTextBox.CommandBindings>

          <CommandBinding Command="Paste" Executed="CommandBinding_Executed"></CommandBinding>

     </RichTextBox.CommandBindings>

    private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
            {
               
            }

    通过这个绑定  可以进入该方法  

    希望大家为我解答一下,感谢大家!

    2017年3月30日 6:24

答案


  • Hi 没事养个哈土奇,

    请尝试以下代码:

    private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
            {
                if (Clipboard.ContainsImage())
                {
                    e.Handled = true;
                    Clipboard.Clear();
                    return;
                }
                //Get Unicode Text
                string paste = Clipboard.GetText();
                Clipboard.Clear();
                Clipboard.SetText(paste);
                MyRichTextBox.Paste();
                e.Handled = true;
            }


    Best Regards,

    Yohann Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2017年3月30日 9:37
    版主

全部回复


  • Hi 没事养个哈土奇,

    请尝试以下代码:

    private void CommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
            {
                if (Clipboard.ContainsImage())
                {
                    e.Handled = true;
                    Clipboard.Clear();
                    return;
                }
                //Get Unicode Text
                string paste = Clipboard.GetText();
                Clipboard.Clear();
                Clipboard.SetText(paste);
                MyRichTextBox.Paste();
                e.Handled = true;
            }


    Best Regards,

    Yohann Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2017年3月30日 9:37
    版主
  • Thanks!
    2017年3月31日 0:33