从 Richtextbox 中的 rtf 复制的问题 [英] Problem for copyn'g from rtf in richtextbox
本文介绍了从 Richtextbox 中的 rtf 复制的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从富文本框中的 rtf 复制时出现问题
I have a problem when copying from rtf in richtextbox
当序列化丢失的财产时.//不序列化属性bold"和color"和size"
when serializing lost property. // NOT SERIALIZE properties "bold" and "color" and "size"
所有代码:
string ConvertXamlToString(FlowDocument fd)
{
string format = "@TAG@{0}:{1}@TAG@";
FlowDocument ss = new FlowDocument();
for (int i = 0; i < fd.Blocks.Count; i++)
{
var block = (fd.Blocks as BlockCollection).ElementAt(i);
if (block is Paragraph)
{
var p = new Paragraph();
for (int y = 0; y < ((Paragraph)block).Inlines.Count; y++)
{
var inline = ((Paragraph)block).Inlines.ElementAt(y);
if (inline is InlineUIContainer)
{
var elem = ((InlineUIContainer)inline).Child;
if (elem is FlashControl)
{
TextBox mc = new TextBox() { Text = string.Format(format, "FlashControl", (elem as FlashControl).Flashp.Source) };
p.Inlines.Add(mc);
}
else if (elem is MusicControl)
{
MusicControl mc = new MusicControl((elem as MusicControl).Path_file);
p.Inlines.Add(mc);
}
else if (elem is Image)
{
Image mc = new Image();
Image Last = (elem as Image);
try
{
if (Last.Source is System.Windows.Media.Imaging.BitmapImage)
{
mc.Source = new BitmapImage(new Uri(((System.Windows.Media.Imaging.BitmapImage)(Last.Source)).UriSource.AbsolutePath));
}
else if(Last.Source is System.Windows.Media.Imaging.BitmapImage)
{
mc.Source = new BitmapImage(new Uri(((System.Windows.Media.Imaging.BitmapImage)(Last.Source)).UriSource.ToString()));
}
}
catch { }
p.Inlines.Add(mc);
}
else
{
p.Inlines.Add(elem);
}
}
else if (inline is Run)
{
Run r = (inline as Run);
string rSer = XamlWriter.Save(r);
var inl1 = XamlReader.Parse(rSer);
p.Inlines.Add(inl1 as Run);
}
else if (inline is Span)
{
Span r = (inline as Span);
string rSer = XamlWriter.Save(r);// NOT SERIALIZE properties "bold" and "color" and "size"
var inl1 = XamlReader.Parse(rSer);
p.Inlines.Add(inl1 as Span);
}
else
{
}
}
ss.Blocks.Add(p);
}
}
string aaa = XamlWriter.Save(ss);
richtextbox.Document.Blocks.Clear();
object f = XamlReader.Parse(aaa);
richtextbox.Document = f as FlowDocument;
return aaa;
}
代码的主要部分:
else if (inline is Run)
{
Run r = (inline as Run);
string rSer = XamlWriter.Save(r);
var inl1 = XamlReader.Parse(rSer);
p.Inlines.Add(inl1 as Run);
}
else if (inline is Span)
{
Span r = (inline as Span);
string rSer = XamlWriter.Save(r);// NOT SERIALIZE properties "bold" and "color" and "size"
var inl1 = XamlReader.Parse(rSer);
p.Inlines.Add(inl1 as Span);
}
如果您手动输入所有内容,则一切正常.我该如何解决这个问题?
if you enter everything manually, all is well. How do I fix this?
推荐答案
嗯,粗体和大小本身并不是属性,它们是 Span
的衍生物,你可能需要解析它们通过迭代 Span
的 Inlines
属性来单独保留它们
Hmm, well bold and size aren't properties as such, they're derivatives of Span
, you might need to parse them individually by iterating the Inlines
property of your Span
to preserve them
这篇关于从 Richtextbox 中的 rtf 复制的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文