wpf - Copy list to Flowdocument messes up 1st listitem -
i'm writing extension allows user merge multiple notes single note , provides features adding periods onto end of original notes. i'm writing code copies parts of 1 flowdocument , inserts periods goes.
i having problems copying lists new document. reason first listitem ends in paragraph preceeding list instead of in list.
my code:
foreach (block b in tempdoc.blocks) { thisblock++; if (b list) { pkhcommon.wpf.helpers.addblock(b, mergeddocument); } else { paragraph p = b paragraph; foreach (inline inl in p.inlines) { if (!(inl linebreak)) pkhcommon.wpf.helpers.addinline(inl, mergeddocument); } if (thiselement != lastelement || thisblock != lastblock) if ((bool)cb_addperiods.ischecked) pkhcommon.wpf.helpers.addinline(new run(". "), mergeddocument); else pkhcommon.wpf.helpers.addinline(new run(" "), mergeddocument); } }
below function merge blocks. addiline function works same way.
public static void addblock(block from, flowdocument to) { if (from != null) { using (system.io.memorystream stream = new system.io.memorystream()) { textrange range = new textrange(from.contentstart, from.contentend); 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); } } }
i can't understand why flowdocument deciding put listitem preceeding paragraph.
adding block flowdocument's block collection should put @ end.
works me.
document.blocks.add(blocktoadd);
you doing save/load clone block right? can try adding way @ end instead of inserting in text range?
var blocktoadd = xamlreader.load(stream) block; document.blocks.add(blocktoadd);
part of issue after saving, stream position @ end of stream, there nothing load. there better way fix out of time help. setting position 0 feels wrong. has no parse exception.
var = new system.windows.documents.list(new listitem(new paragraph(new run("blah")))); using (var stream = new memorystream()) { system.windows.markup.xamlwriter.save(from, stream); stream.position = 0; block b = system.windows.markup.xamlreader.load(stream) block; }
Comments
Post a Comment