How to prevent certain kinds of formatting from getting pasted into WPF RichTextBox -


i want allow simple formatting commands within wpf richtextbox not others.

i've created toolbar allows users apply bold or italics, , use bulleted or numbered lists. (basically, want support formatting commands appropriate blog or wiki.)

the problem users can perform cut , paste operations insert text foreground , background colors, among other kinds of disallowed formatting. can lead nasty usability issues users pasting white text onto white background.

is there way turn these advanced formatting features off? if not, there way can intercept paste operation , strip out formatting don't want?

you can intercept paste operation this:

    void addpastehandler()     {         dataobject.addpastinghandler(richtextbox, new dataobjectpastingeventhandler(onpaste));     }      void onpaste(object sender, dataobjectpastingeventargs e)     {         if (!e.sourcedataobject.getdatapresent(dataformats.rtf, true)) return;         var rtf = e.sourcedataobject.getdata(dataformats.rtf) string;         // change e.sourcedataobject strip non-basic formatting...     } 

and messy part keeping not of formatting. rtf variable string in rtf format can use third-party libary parse, walk tree using dom-like pattern, , emit new rtf text, bold , italics. cram e.sourcedataobject or number of other options (see docs below).

here pastinghandler docs:

here 1 of many rtf parsers:


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -