Ichtextarea provides an extremely rich text box.
It is extremely important for us to develop an online website content writer or chat program to display messages. The following is a brief introduction of some of my code in practical applications. I hope it will be helpful for future development.
// Can accommodate any uielement
Inlineuicontainer Ic = new inlineuicontainer ();
Image IMG = new image ();
IMG. Source = new bitmapimage (New uri ("icon_biggrin.png", urikind. relativeorabsolute ));
IC. Child = IMG;
RTA. selection. insert (IC );
// Paragraph Pg = new paragraph ();
// Pg. inlines. Add ("text ");
//// Get it offline
// Pg. textdecorations = textdecorations. Underline;
// RTA. blocks. Add (PG );
Hyperlink HL = new hyperlink ();
// Run can be inserted in any inlines
Hl. inlines. Add (new run () {text = "this is a link "});
Hl. navigateuri = new uri ("http://funsl.com", urikind. Absolute );
RTA. selection. insert (HL );
Bytes ---------------------------------------------------------------------------------------------------------------------------
Operations on the selected content:
If (RichTextBox. selection. Text. length> 0)
{
// Change the color
Dependencyproperty property = textelement. foregroundproperty;
VaR value = (Brush) RichTextBox. selection. getpropertyvalue (property );
// The tag is color.
VaR newvalue = new solidcolorbrush (color) (rectangle) cbb_colors.selecteditem). Tag );
RichTextBox. selection. setpropertyvalue (property, newvalue );
}
Bytes -----------------------------------------------------------------------------------------------------------------------------
If (RichTextBox. selection. Text. length> 0)
{
// Reduce the font size
Dependencyproperty property = textelement. fontsizeproperty;
VaR value = (double) RichTextBox. selection. getpropertyvalue (property );
VaR newvalue = value-5;
RichTextBox. selection. setpropertyvalue (property, newvalue );
}
Bytes -----------------------------------------------------------------------------------------------------------------------------
If (RichTextBox. selection. Text. length> 0)
{
// Increase the font size
Dependencyproperty property = textelement. fontsizeproperty;
VaR value = (double) RichTextBox. selection. getpropertyvalue (property );
VaR newvalue = value + 5;
RichTextBox. selection. setpropertyvalue (property, newvalue );
}
Bytes -----------------------------------------------------------------------------------------------------------------------------
// Deprecate
Dependencyproperty property = textelement. textdecorationsproperty;
VaR value = RichTextBox. selection. getpropertyvalue (property );
Textdecorationcollection newvalue = textdecorations. Underline;
If (value! = NULL & value! = Dependencyproperty. unsetvalue)
{
Newvalue = NULL;
}
RichTextBox. selection. setpropertyvalue (textelement. textdecorationsproperty, newvalue );
Bytes -----------------------------------------------------------------------------------------------------------------------------
// Italic
VaR bolddp = textelement. fontweightproperty;
VaR value = RichTextBox. selection. getpropertyvalue (bolddp );
VaR newvalue = fontweights. Bold;
If (value! = Dependencyproperty. unsetvalue & (fontweight) value) = fontweights. Bold)
{
// Untoggle bold if already set
Newvalue = fontweights. normal;
}
// Set new bold Value
RichTextBox. selection. setpropertyvalue (bolddp, newvalue );
Bytes -----------------------------------------------------------------------------------------------------------------------------
// Bold
Dependencyproperty property = textelement. fontstyleproperty;
VaR value = RichTextBox. selection. getpropertyvalue (property );
VaR newvalue = fontstyles. italic;
If (value! = Dependencyproperty. unsetvalue & (fontstyle) value) = fontstyles. italic)
{
Newvalue = fontstyles. normal;
}
RichTextBox. selection. setpropertyvalue (property, newvalue );
Bytes -----------------------------------------------------------------------------------------------------------------------------