Silverlight 4 richtextarea

Source: Internet
Author: User
Tags silverlight

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 -----------------------------------------------------------------------------------------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.