TextSelection.ApplyPropertyValue Method


Applies the specified formatting property and value to the current selection.

Namespace:  System.Windows.Documents
Assembly:  System.Windows (in System.Windows.dll)

public void ApplyPropertyValue(
	DependencyProperty formattingProperty,
	Object value


Type: System.Windows.DependencyProperty
A formatting property to apply.
Type: System.Object
The value for the formatting property.

This method applies specified formatting by inserting the appropriate Inline elements, such as Bold and Italic, into this TextSelection. Sometimes the ApplyPropertyValue method may modify or convert TextElement objects when it applies the specified formatting values. For example, a Span element may be converted to a Run element or similar property values may be combined to normalize them.

The following code uses the ApplyPropertyValue method to apply Italic formatting to selected content in a RichTextBox. This code example is a part of a larger example used in the TextSelection class.

Run this sample

//Set Italic formatting to selected content
private void BtnItalic_Click(object sender, RoutedEventArgs e)
    if (MyRTB != null)
        if (MyRTB.Selection.GetPropertyValue(Run.FontStyleProperty) is FontStyle && ((FontStyle)MyRTB.Selection.GetPropertyValue(Run.FontStyleProperty)) == FontStyles.Normal)
            MyRTB.Selection.ApplyPropertyValue(Run.FontStyleProperty, FontStyles.Italic);
            MyRTB.Selection.ApplyPropertyValue(Run.FontStyleProperty, FontStyles.Normal);



Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.