Export (0) Print
Expand All

TextSelection.ApplyPropertyValue Method

Silverlight

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

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

'Declaration
Public Sub ApplyPropertyValue ( _
	formattingProperty As DependencyProperty, _
	value As Object _
)

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.

Run this sample


    'Set Italic formatting to selected content
    Private Sub BtnItalic_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        If MyRTB IsNot Nothing Then
            If TypeOf MyRTB.Selection.GetPropertyValue(Run.FontStyleProperty) Is FontStyle _
                AndAlso (CType(MyRTB.Selection.GetPropertyValue(Run.FontStyleProperty), FontStyle) = FontStyles.Normal) Then
                MyRTB.Selection.ApplyPropertyValue(Run.FontStyleProperty, FontStyles.Italic)
            Else
                MyRTB.Selection.ApplyPropertyValue(Run.FontStyleProperty, FontStyles.Normal)
            End If
        End If
    End Sub



Silverlight

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.

Community Additions

ADD
Show:
© 2015 Microsoft