本文整理汇总了C#中System.Windows.Documents.TextRange.SetXmlVirtual方法的典型用法代码示例。如果您正苦于以下问题:C# TextRange.SetXmlVirtual方法的具体用法?C# TextRange.SetXmlVirtual怎么用?C# TextRange.SetXmlVirtual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextRange
的用法示例。
在下文中一共展示了TextRange.SetXmlVirtual方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
internal static void Load(TextRange thisRange, Stream stream, string dataFormat)
{
if (stream == null)
{
throw new ArgumentNullException("stream");
}
if (dataFormat == null)
{
throw new ArgumentNullException("dataFormat");
}
NormalizeRange(thisRange);
// Reset the stream position to the beginning
if (stream.CanSeek)
{
stream.Seek(0, SeekOrigin.Begin);
}
if (dataFormat == DataFormats.Text)
{
StreamReader textStreamReader = new StreamReader(stream);
string text = textStreamReader.ReadToEnd();
thisRange.Text = text;
}
else if (dataFormat == DataFormats.Xaml)
{
StreamReader xamlStreamReader = new StreamReader(stream);
string xamlText = xamlStreamReader.ReadToEnd();
thisRange.Xml = xamlText;
}
else if (dataFormat == DataFormats.XamlPackage && SecurityHelper.CheckUnmanagedCodePermission())
{
object element = WpfPayload.LoadElement(stream);
if (!(element is Section) && !(element is Span))
{
throw new ArgumentException(SR.Get(SRID.TextRange_UnrecognizedStructureInDataFormat, dataFormat), "stream");
}
thisRange.SetXmlVirtual((TextElement)element);
}
else if (dataFormat == DataFormats.Rtf && SecurityHelper.CheckUnmanagedCodePermission())
{
//
StreamReader rtfStreamReader = new StreamReader(stream);
string rtfText = rtfStreamReader.ReadToEnd();
MemoryStream memoryStream = TextEditorCopyPaste.ConvertRtfToXaml(rtfText);
if (memoryStream == null)
{
throw new ArgumentException(SR.Get(SRID.TextRange_UnrecognizedStructureInDataFormat, dataFormat), "stream");
}
TextElement textElement = WpfPayload.LoadElement(memoryStream) as TextElement;
if (!(textElement is Section) && !(textElement is Span))
{
throw new ArgumentException(SR.Get(SRID.TextRange_UnrecognizedStructureInDataFormat, dataFormat), "stream");
}
thisRange.SetXmlVirtual(textElement);
}
else
{
// Unsupported format - thows exception
throw new ArgumentException(SR.Get(SRID.TextRange_UnsupportedDataFormat, dataFormat), "dataFormat");
}
}