本文整理汇总了C#中System.Windows.Documents.TextRange.CanLoad方法的典型用法代码示例。如果您正苦于以下问题:C# TextRange.CanLoad方法的具体用法?C# TextRange.CanLoad怎么用?C# TextRange.CanLoad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextRange
的用法示例。
在下文中一共展示了TextRange.CanLoad方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: thr_load
private void thr_load(object obj)
{
Dispatcher.BeginInvoke(new Action(delegate
{
string date = cmbHistoryList.SelectedValue.ToString();
string[] files = Directory.GetFiles(Constants.HISTORYDIR, "*" +windowName+"_"+date + ".hist");
string file = files[0];
TextRange tr = new TextRange(usrRTB.richChat.Document.ContentStart, usrRTB.richChat.Document.ContentEnd);
using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, bufferSize: 4096, useAsync: true))
{
if (tr.CanLoad(DataFormats.XamlPackage))
{
tr.Load(fs, DataFormats.XamlPackage);
}
}
foreach (Block b in usrRTB.richChat.Document.Blocks) {
b.TextAlignment = TextAlignment.Left;
}
}));
}
示例2: SetRangeContent
private string SetRangeContent(TextRange selection, string content)
{
string loadType = DataFormats.Rtf;
IsFormatted = true;
content = content == "" ? " " : content;
try
{
using (MemoryStream ms = new MemoryStream(ASCIIEncoding.Default.GetBytes(content)))
{
if (content.StartsWith("<Section"))
{
if (selection.CanLoad(DataFormats.Xaml))
{
selection.Load(ms, DataFormats.Xaml);
loadType = DataFormats.Xaml;
}
}
else if (content.StartsWith("PK"))
{
if (selection.CanLoad(DataFormats.XamlPackage))
{
selection.Load(ms, DataFormats.XamlPackage);
loadType = DataFormats.XamlPackage;
}
}
else if (content.StartsWith("{\\rtf"))
{
if (selection.CanLoad(DataFormats.Rtf))
{
selection.Load(ms, DataFormats.Rtf);
loadType = DataFormats.Rtf;
}
}
else
{
if (selection.CanLoad(DataFormats.Text))
{
selection.Load(ms, DataFormats.Text);
loadType = DataFormats.Text;
IsFormatted = false;
}
}
}
}
catch (Exception)
{
throw;
}
return loadType;
}
示例3: Window_Loaded
private void Window_Loaded(object sender, RoutedEventArgs e)
{
TextPointer start = this._rtb.Document.ContentStart,
end = this._rtb.Document.ContentEnd;
TextRange tr = new TextRange(start, end);
FileInfo fi = new FileInfo("proba.xaml");
if (tr.CanLoad(DataFormats.Xaml) && fi.Exists)
{
using (Stream s = fi.Open(FileMode.Open))
{
SetDefaultColorOfTextInXmlStream(s);
tr.Load(s, DataFormats.Xaml);
}
}
}
示例4: SetDocumentContent
static TextRange SetDocumentContent(FlowDocument document, string text, string dataFormat)
{
var content = new TextRange(document.ContentStart, document.ContentEnd);
if (content.CanLoad(dataFormat))
{
if (string.IsNullOrEmpty(text))
{
content.Text = text;
}
else
{
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(text)))
{
content.Load(stream, dataFormat);
}
}
}
return content;
}
示例5: Load
public void Load(TextRange storyText)
{
// Data format for the person's story file.
string dataFormat = DataFormats.Rtf;
if (File.Exists(this.AbsolutePath))
{
try
{
// Open the file for reading
using (FileStream stream = File.OpenRead(this.AbsolutePath))
{
if (storyText.CanLoad(dataFormat))
storyText.Load(stream, dataFormat);
}
}
catch
{
// Could not load the story. Handle all exceptions
// the same, ignore and continue.
}
}
}
示例6: PasteTextDataToRichTextBox
// Paste text data on RichTextBox as UTF8 encoding
private bool PasteTextDataToRichTextBox(string dataFormat, string textData)
{
var pasted = false;
var document = richTextBox.Document;
var textRange = new TextRange(document.ContentStart, document.ContentEnd);
Stream stream = new MemoryStream();
var bytesUnicode = Encoding.Unicode.GetBytes(textData);
var bytes = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, bytesUnicode);
if (bytes.Length > 0 && textRange.CanLoad(dataFormat))
{
stream.Write(bytes, 0, bytes.Length);
textRange.Load(stream, dataFormat);
pasted = true;
}
return pasted;
}
示例7: MenuItemLaden_Click
private void MenuItemLaden_Click(object sender, RoutedEventArgs e)
{
try
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Earthdawncharakterarchiv (*.edz)|*.edz";
if (open.ShowDialog() == true)
{
using (ZipArchive zip = ZipFile.Open(open.FileName, ZipArchiveMode.Read))
{
foreach (ZipArchiveEntry entry in zip.Entries)
{
if(entry.Name.Contains(".bin"))
{
Stream sfs = entry.Open();
BinaryFormatter formatter = new BinaryFormatter();
aktChar = (EDChar)formatter.Deserialize(sfs);
sfs.Close();
}
else if (entry.Name.Contains(".xaml"))
{
Stream nfs = entry.Open();
TextRange rng = new TextRange(Notizen.ContentStart, Notizen.ContentEnd);
if (rng.CanLoad(DataFormats.Xaml))
{
rng.Load(nfs, DataFormats.Xaml);
}
nfs.Close();
}
}
}
UpdateGUI();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例8: OnClick_LoadScript
private void OnClick_LoadScript(object sender, RoutedEventArgs e)
{
System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
dlg.AddExtension = true;
dlg.DefaultExt = ".bql";
dlg.Title = "Specify the script file";
dlg.Filter = "Building Query Language|*.bql";
dlg.FilterIndex = 0;
dlg.ValidateNames = true;
dlg.FileOk += delegate(object s, System.ComponentModel.CancelEventArgs eArg)
{
Stream file = null;
string dataFormat = "Text";
try
{
file = dlg.OpenFile();
TextRange txtRange = new TextRange(ScriptText.Document.ContentStart, ScriptText.Document.ContentEnd);
if (txtRange.CanLoad(dataFormat))
{
txtRange.Load(file, dataFormat);
}
this.Title = "BQL Console - " + System.IO.Path.GetFileName(dlg.FileName);
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(string.Format("Loading script from file failed : {0}.", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
if (file != null)
file.Close();
}
};
dlg.ShowDialog();
ScriptText.RefreshKeyColour();
}