Freigeben über


TextSelection.Xaml Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the XAML representation of the current selection.

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

Syntax

'Declaration
Public Property Xaml As String
public string Xaml { get; set; }

Property Value

Type: System.String
A String that is a XAML representation of the current selection. This XAML representation is the same XAML that is applied to the clipboard for a copy operation.

Remarks

This property replaces the current selection with the XAML representation of that content. It inserts the XAML representation at the current position if there is no selection or an empty selection.

Examples

The following code shows how you can use the Xaml property to display the XAML markup of the content in a RichTextBox. This code example is a part of a larger sample used in the Silverlight Text Editor Sample topic.

'Set the xamlTb TextBox with the current XAML of the RichTextBox and make it visible. Any changes to the XAML made 
'in xamlTb is also reflected back on the RichTextBox. Note that the Xaml string returned by RichTextBox.Xaml will 
'not include any UIElement contained in the current RichTextBox. Hence the UIElements will be lost when you 
'set the Xaml back again from the xamlTb to the RichTextBox.

Public Sub btnMarkUp_Checked(ByVal sender As Object, ByVal e As RoutedEventArgs)
    If btnMarkUp.IsChecked.Value Then
        xamlTb.Visibility = System.Windows.Visibility.Visible
        xamlTb.IsTabStop = True
        xamlTb.Text = rtb.Xaml
    Else
        rtb.Xaml = xamlTb.Text
        xamlTb.Visibility = System.Windows.Visibility.Collapsed
        xamlTb.IsTabStop = False

    End If
End Sub
//Set the xamlTb TextBox with the current XAML of the RichTextBox and make it visible. Any changes to the XAML made 
//in xamlTb is also reflected back on the RichTextBox. Note that the Xaml string returned by RichTextBox.Xaml will 
//not include any UIElement contained in the current RichTextBox. Hence the UIElements will be lost when we 
//set the Xaml back again from the xamlTb to the RichTextBox.
public void btnMarkUp_Checked(object sender, RoutedEventArgs e)
{
    if (btnMarkUp.IsChecked.Value)
    {
        xamlTb.Visibility = System.Windows.Visibility.Visible;
        xamlTb.IsTabStop = true;
        xamlTb.Text = rtb.Xaml;
    }
    else
    {
        rtb.Xaml = xamlTb.Text;
        xamlTb.Visibility = System.Windows.Visibility.Collapsed;
        xamlTb.IsTabStop = false;
    }

}

Version Information

Silverlight

Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

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