我只需要在主代码中获取 FlowDocument ...
我喜欢这样,但没有成功
this.flowDoc = engine.CreateFlowDocument(contentItems); // Can't compile
public async Task<FlowDocument> CreateFlowDocument(ContentItems contentItems)
{ return await Task.Run(() =>
{
try
{
var fd = new FlowDocument();
foreach (var item in contentItems.Items)
{
if (item.ContentType == ContentTypes.Header)
{
var paraHeader = new Paragraph();
paraHeader.FontSize = 14;
paraHeader.Foreground = Brushes.Black;
paraHeader.FontWeight = FontWeights.Bold;
paraHeader.Inlines.Add(new Run(item.Data));
fd.Blocks.Add(paraHeader);
}
if (item.ContentType == ContentTypes.Paragraph)
{
var paragraph = new Paragraph();
paragraph.FontSize = 12;
paragraph.Foreground = Brushes.Black;
paragraph.FontWeight = FontWeights.Normal;
paragraph.Inlines.Add(new Run(item.Data));
fd.Blocks.Add(paragraph);
}
}
return fd;
}
catch (Exception) { }
return new FlowDocument();
}
);
}