#251 – 在FlowDocument中嵌入UIElement (Embedding an UIElement Within a FlowDocument)

你可以通过使用BlockUIContainerFlowDocument 中嵌入任何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/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值