你可以通过使用BlockUIContainer 在FlowDocument 中嵌入任何UIElement 。这样允许在文档中插入控件来显示。因为Panel 继承自UIElement,因此你不仅可以嵌入单个的控件,还可以通过Panel 作为容器嵌入更多的控件。
下面是一个例子:
<FlowDocument FontFamily="Cambria" FontSize="14">
<Paragraph>"Be who you are and say what you feel, because those who mind don't matter, and those who matter don't mind.
— Dr. Seuss</Paragraph>
<BlockUIContainer FontFamily="Arial" FontSize="12">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Content="Like it" Margin="10" Width="70" Height="25"/>
<Button Content="Don't like it" Margin="10" Width="70" Height="25"/>
</StackPanel>
</BlockUIContainer>
<Paragraph>We continue this document with some more lovely Dr. Seuss quotes..</Paragraph>
</FlowDocument>
下面是运行后文档的显示结果:
在上面的例子中通过BlockUIContainer 放入了一个StatckPanel ,而在StatckPanel 中放入了两个Button ,这样就在文档中插入了两个按钮。
原文地址:https://wpf.2000things.com/2011/03/20/251-embedding-an-uielement-into-a-flowdocument/