TextSelection.ApplyPropertyValue Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Applies the specified formatting property and value to the current selection.
Assembly: System.Windows (in System.Windows.dll)
Parameters
- formattingProperty
- Type: System.Windows.DependencyProperty
A formatting property to apply.
- value
- 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.
//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); else MyRTB.Selection.ApplyPropertyValue(Run.FontStyleProperty, FontStyles.Normal); } }