TextRange.Load(Stream, String) Método

Definición

Carga la selección actual en un formato de datos especificado de una secuencia especificada.

C#
public void Load(System.IO.Stream stream, string dataFormat);

Parámetros

stream
Stream

Secuencia legible que contiene datos para cargar en la selección actual.

dataFormat
String

Formato de datos con el que cargar los datos. Los formatos de datos actualmente compatibles son Rtf, Text, Xaml y XamlPackage.

Excepciones

Se produce cuando el objeto stream o dataFormat es null.

Se produce cuando el formato de datos especificado no es compatible. También puede producirse si el contenido cargado de stream no coincide con el formato de datos especificado.

Ejemplos

En el siguiente ejemplo se muestra el uso del método Load.

C#
// This method accepts an input stream and a corresponding data format.  The method
// will attempt to load the input stream into a TextRange selection, apply Bold formatting
// to the selection, save the reformatted selection to an alternat stream, and return 
// the reformatted stream.  
Stream BoldFormatStream(Stream inputStream, string dataFormat)
{
    // A text container to read the stream into.
    FlowDocument workDoc = new FlowDocument();
    TextRange selection = new TextRange(workDoc.ContentStart, workDoc.ContentEnd);
    Stream outputStream = new MemoryStream();

    try
    {
        // Check for a valid data format, and then attempt to load the input stream
        // into the current selection.  Note that CanLoad ONLY checks whether dataFormat
        // is a currently supported data format for loading a TextRange.  It does not 
        // verify that the stream actually contains the specified format.  An exception 
        // may be raised when there is a mismatch between the specified data format and 
        // the data in the stream. 
        if (selection.CanLoad(dataFormat))
            selection.Load(inputStream, dataFormat);
    }
    catch (Exception e) { return outputStream; /* Load failure; return a null stream. */ }

    // Apply Bold formatting to the selection, if it is not empty.
    if (!selection.IsEmpty)
        selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);

    // Save the formatted selection to a stream, and return the stream.
    if (selection.CanSave(dataFormat))
        selection.Save(outputStream, dataFormat);

    return outputStream;
}

Comentarios

Si CanSeek es true para stream, el contenido se cargará desde el principio de la secuencia hasta el final de la secuencia. De lo contrario, el contenido se leerá del actual Position al final de la secuencia. Cuando este método devuelve , stream se deja abierto y la posición actual dentro stream de no está definida.

Una operación de carga reemplaza la selección actual por el contenido recién cargado.

Se aplica a

Producto Versiones
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Consulte también