本文整理汇总了C#中System.Windows.Documents.TextRange.Load方法的典型用法代码示例。如果您正苦于以下问题:C# TextRange.Load方法的具体用法?C# TextRange.Load怎么用?C# TextRange.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextRange
的用法示例。
在下文中一共展示了TextRange.Load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadPost
public void LoadPost(string postFile)
{
FileStream fileStream = new FileStream(postFile, FileMode.Open);
TextRange range = new TextRange(_postEdit.Document.ContentStart, _postEdit.Document.ContentEnd);
range.Load(fileStream, DataFormats.Rtf);
fileStream.Close();
}
示例2: SetText
/// <summary>
/// Converts the XHtml content to XAML and sets the converted content in a flow document.
/// </summary>
/// <param name="document">The flow document in which the XHtml content has to be loaded.</param>
/// <param name="text">The Unicode UTF-8 coded XHtml text to load.</param>
/// <exception cref="InvalidDataException">When an error occured while parsing xaml code.</exception>
public void SetText(FlowDocument document, string text)
{
try
{
if (!string.IsNullOrEmpty(text))
{
XDocument xDocument = XDocument.Parse(text);
string xaml = HtmlToXamlConverter.ConvertXHtmlToXaml(xDocument, false);
TextRange tr = new TextRange(document.ContentStart, document.ContentEnd);
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xaml)))
{
tr.Load(ms, DataFormats.Xaml);
}
_xHtml = text;
}
}
catch (Exception e)
{
// todo tb: Logging
//log.Error("Data provided is not in the correct Xaml or XHtml format: {0}", e);
throw e;
}
}
示例3: FlowDocumentFromBase64String
public static FlowDocument FlowDocumentFromBase64String(this string data)
{
FlowDocument FD = new FlowDocument();//Need to fix Possible MemLeak
if (data == null) return FD;
//FD = (FlowDocument)XamlReader.Parse(data);
byte[] content;
TextRange tr = new TextRange(FD.ContentStart, FD.ContentEnd);
//convert string to MemoryStream
if (data.StartsWith("{"))
{
content = new byte[data.Length + sizeof(char)];
Buffer.BlockCopy(data.ToCharArray(), 0, content, 0, content.Length);
MemoryStream ms = new MemoryStream(content);
tr.Load(ms, System.Windows.DataFormats.Rtf);
}
else
{
content = Convert.FromBase64String(data);
MemoryStream ms = new MemoryStream(content);
tr.Load(ms, System.Windows.DataFormats.XamlPackage);
}
return FD;
//SQLData = ASCIIEncoding.Default.GetString(ms.ToArray());
//You can save this data to SQLServer
}
示例4: Button_Click_1
private void Button_Click_1(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
fs = File.Open(new Uri(ofd.FileName).LocalPath, FileMode.Open);
int length, offset;
length = int.Parse(tbxlength.Text);
offset = int.Parse(tbxoffset.Text);
byte[] buffer = new byte[offset];
fs.Read(buffer,0,offset);
TextRange tr = new TextRange(tbxPrevious.Document.ContentStart, tbxPrevious.Document.ContentEnd);
using(MemoryStream ms = new MemoryStream(buffer))
{
tr.Load(ms, DataFormats.Rtf);
}
buffer = new byte[length];
fs.Read(buffer, 0, length);
tr = new TextRange(tbxTarget.Document.ContentStart, tbxTarget.Document.ContentEnd);
using (MemoryStream ms = new MemoryStream(buffer))
{
tr.Load(ms, DataFormats.Rtf);
}
buffer = new byte[fs.Length - fs.Position];
fs.Read(buffer, 0, buffer.Length);
tr = new TextRange(tbxNext.Document.ContentStart, tbxNext.Document.ContentEnd);
using (MemoryStream ms = new MemoryStream(buffer))
{
tr.Load(ms, DataFormats.Rtf);
}
fs.Close();
}
示例5: ConvertRtfToXaml
private static string ConvertRtfToXaml(string rtfText)
{
var richTextBox = new RichTextBox();
if (string.IsNullOrEmpty(rtfText)) return "";
var textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
//Create a MemoryStream of the Rtf content
using (var rtfMemoryStream = new MemoryStream())
{
using (var rtfStreamWriter = new StreamWriter(rtfMemoryStream))
{
rtfStreamWriter.Write(rtfText);
rtfStreamWriter.Flush();
rtfMemoryStream.Seek(0, SeekOrigin.Begin);
//Load the MemoryStream into TextRange ranging from start to end of RichTextBox.
textRange.Load(rtfMemoryStream, DataFormats.Rtf);
}
}
using (var rtfMemoryStream = new MemoryStream())
{
textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
textRange.Save(rtfMemoryStream, DataFormats.Xaml);
rtfMemoryStream.Seek(0, SeekOrigin.Begin);
using (var rtfStreamReader = new StreamReader(rtfMemoryStream))
{
return rtfStreamReader.ReadToEnd();
}
}
}
示例6: OnBoundDocumentChanged
private static void OnBoundDocumentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
RichTextBox box = d as RichTextBox;
if (box == null)
return;
RemoveEventHandler(box);
var bytes = e.NewValue as byte[];
box.Document.Blocks.Clear();
if(bytes != null && bytes.Length > 0)
{
TextRange textRange = new TextRange(box.Document.ContentStart, box.Document.ContentEnd);
using (MemoryStream ms = new MemoryStream())
{
ms.Write(bytes,0, bytes.Length);
textRange.Load(ms, DataFormats.Rtf);
}
}
AttachEventHandler(box);
}
示例7: AddBlock
public static void AddBlock(Block from, FlowDocument to)
{
if (from != null)
{
//if (from is ItemsContent)
//{
// ((ItemsContent)from).RunBeforeCopy();
//}
//else
{
TextRange range = new TextRange(from.ContentStart, from.ContentEnd);
MemoryStream stream = new MemoryStream();
System.Windows.Markup.XamlWriter.Save(range, stream);
range.Save(stream, DataFormats.XamlPackage);
TextRange textRange2 = new TextRange(to.ContentEnd, to.ContentEnd);
textRange2.Load(stream, DataFormats.XamlPackage);
}
}
}
示例8: SetText
public void SetText(FlowDocument document, string text) {
var newText = ChatToXamlConverter.Convert(text);
var tr = new TextRange(document.ContentStart, document.ContentEnd);
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(newText)))
tr.Load(ms, DataFormats.Xaml);
}
示例9: OnBoundDocumentChanged
private static void OnBoundDocumentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
RichTextBox box = d as RichTextBox;
if (box == null)
return;
RemoveEventHandler(box);
string newXAML = e.NewValue as string;
box.Document.Blocks.Clear();
if (!string.IsNullOrEmpty(newXAML))
{
TextRange tr = new TextRange(box.Document.ContentStart, box.Document.ContentEnd);
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);
sw.Write(newXAML);
sw.Flush();
tr.Load(ms, DataFormats.Rtf);
sw.Close();
ms.Close();
}
AttachEventHandler(box);
}
示例10: AbrirMenuItem_Click
private void AbrirMenuItem_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.DefaultExt = ".txt";
dlg.Filter = "Text documents (.txt)|*.txt";
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
TextRange range;
System.IO.FileStream fStream;
if (System.IO.File.Exists(dlg.FileName))
{
range = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd);
fStream = new System.IO.FileStream(dlg.FileName, System.IO.FileMode.OpenOrCreate);
range.Load(fStream, System.Windows.DataFormats.Rtf);
fStream.Close();
archivo = dlg.FileName;
}
}
}
示例11: LoadData
public void LoadData()
{
string Narr;
string NarrFormat;
if (mIsSummaryNarrative)
{
Narr = mDataSet.Tables["i9Narrative"].Rows[0]["SummaryNarrative"].ToString();
NarrFormat = mDataSet.Tables["i9Narrative"].Rows[0]["SummaryNarrativeFormat"].ToString();
}
else
{
Narr = mDataSet.Tables["i9Narrative"].Rows[0]["Narrative"].ToString();
NarrFormat = mDataSet.Tables["i9Narrative"].Rows[0]["NarrativeFormat"].ToString();
}
if (String.IsNullOrEmpty(NarrFormat.Trim()) == false)
{
// convert string to stream
byte[] byteArray = Encoding.ASCII.GetBytes(NarrFormat);
using (MemoryStream stream = new MemoryStream(byteArray))
{
TextRange range = new TextRange(mainRTB.Document.ContentStart, mainRTB.Document.ContentEnd);
range.Load(stream, DataFormats.Rtf);
}
}
}
示例12: ConvertRtfToXaml
public static string ConvertRtfToXaml(string rtfText)
{
var richTextBox = new System.Windows.Controls.RichTextBox();
if (string.IsNullOrEmpty(rtfText))
return String.Empty;
var textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
using (var rtfMemoryStream = new MemoryStream())
{
using (var rtfStreamWriter = new StreamWriter(rtfMemoryStream))
{
rtfStreamWriter.Write(rtfText);
rtfStreamWriter.Flush();
rtfMemoryStream.Seek(0, SeekOrigin.Begin);
textRange.Load(rtfMemoryStream, DataFormats.Rtf);
}
}
using (var rtfMemoryStream = new MemoryStream())
{
textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
textRange.Save(rtfMemoryStream, System.Windows.DataFormats.Xaml);
rtfMemoryStream.Seek(0, SeekOrigin.Begin);
using (var rtfStreamReader = new StreamReader(rtfMemoryStream))
{
return rtfStreamReader.ReadToEnd();
}
}
}
示例13: GetPaginator
/// <summary>
/// 获取文档分页器
/// </summary>
/// <param name="pageWidth"></param>
/// <param name="pageHeight"></param>
/// <returns></returns>
public DocumentPaginator GetPaginator(double pageWidth,double pageHeight)
{
//将RichTextBox的文档内容转为XAML
TextRange originalRange = new TextRange(
_textBox.Document.ContentStart,
_textBox.Document.ContentEnd
);
MemoryStream memoryStream = new MemoryStream();
originalRange.Save(memoryStream, System.Windows.DataFormats.XamlPackage);
//根据XAML将流文档复制一份
FlowDocument copy = new FlowDocument();
TextRange copyRange = new TextRange(
copy.ContentStart,
copy.ContentEnd
);
copyRange.Load(memoryStream, System.Windows.DataFormats.XamlPackage);
DocumentPaginator paginator =
((IDocumentPaginatorSource)copy).DocumentPaginator;
//转换为新的分页器
return new PrintingPaginator(
paginator,new Size( pageWidth,pageHeight),
new Size(DPI,DPI)
);
}
示例14: LoadCompleted
private void LoadCompleted(object sender, RoutedEventArgs e)
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
if (!string.IsNullOrEmpty(path))
{
var legalReleasePath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), "legal_release.txt");
try
{
if (File.Exists(legalReleasePath))
{
var textRange = new TextRange(RtfContainer.Document.ContentStart,
RtfContainer.Document.ContentEnd);
using (var fileStream = new FileStream(legalReleasePath, FileMode.Open, FileAccess.Read))
{
textRange.Load(fileStream, DataFormats.Text);
}
}
else
throw new FileNotFoundException("legal_release.txt");
}
catch (Exception ex)
{
ServiceManager.LogError("Load Legal release", ex);
}
}
}
示例15: open_button_Click
private void open_button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
openFileDialog1.Filter = @"Evennote File(*.note)|*.note";
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == true)
{
Note temp = Evennote.OpenNoteFromFile(openFileDialog1.FileName);
titleTextBox.Text = temp.Title;
using (MemoryStream mem = new MemoryStream())
{
TextRange range = new TextRange(temp.Text.ContentStart,
temp.Text.ContentEnd);
range.Save(mem, DataFormats.XamlPackage);
mem.Position = 0;
TextRange kange = new TextRange(richTextBox.Document.ContentStart,
richTextBox.Document.ContentEnd);
kange.Load(mem, DataFormats.XamlPackage);
}
}
}