GetPropertyValue Method
Collapse the table of content
Expand the table of content

TextSelection.GetPropertyValue Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets the value of the specified formatting property on the current selection.

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

public Object GetPropertyValue(
	DependencyProperty formattingProperty
)

Parameters

formattingProperty
Type: System.Windows.DependencyProperty
A formatting property to get the value of on the current selection.

Return Value

Type: System.Object
An object that indicates the value of the specified formatting property on the current selection.

To return a property value, the entire TextSelection must extend over text with only one value for the formattingProperty. If the TextSelection extends over text with two or more different values for the formattingProperty, UnsetValue is returned.

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


//Set Bold formatting to selected content
private void BtnBold_Click(object sender, RoutedEventArgs e)
{
    if (MyRTB != null)
    {
        if (MyRTB.Selection.GetPropertyValue(Run.FontWeightProperty) is FontWeight && ((FontWeight)MyRTB.Selection.GetPropertyValue(Run.FontWeightProperty)) == FontWeights.Normal)
            MyRTB.Selection.ApplyPropertyValue(Run.FontWeightProperty, FontWeights.Bold);
        else
            MyRTB.Selection.ApplyPropertyValue(Run.FontWeightProperty, FontWeights.Normal);

    }

}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Show:
© 2017 Microsoft