簡體   English   中英

WPF中FlowDocument中UIElement的絕對定位

[英]Absolute positioning of UIElement in FlowDocument in WPF

我希望在Hyperlink上出現一個Button 如您所見,它現在是FlowDocument一部分,位於超鏈接旁邊! 但我希望它具有絕對位置,以便它可以顯示在超鏈接上! 我怎樣才能做到這一點?

<FlowDocumentScrollViewer>
    <FlowDocument>
        <Paragraph>
            The maximum speed is
            <Hyperlink>150</Hyperlink>
            <InlineUIContainer>
                <Button>No way!</Button>
            </InlineUIContainer>
            in this road!
        </Paragraph>
    </FlowDocument>
</FlowDocumentScrollViewer>

您可以使用StackPanel來“堆疊”從UIElement繼承的多個對象。 Hyperlink不是從UIElement繼承的,但是您可以通過將超Hyperlink放置在ContentControl來解決此問題。

這是一個工作示例:

<FlowDocumentScrollViewer>
    <FlowDocument>
        <Paragraph>
            The maximum speed is
            <StackPanel>
                <Button>No way!</Button>
                <ContentControl HorizontalAlignment="Center">
                    <Hyperlink>150</Hyperlink>
                </ContentControl>
            </StackPanel>
            in this road!
        </Paragraph>
    </FlowDocument>
</FlowDocumentScrollViewer>

編輯的代碼,其中“ Button出現在“ Hyperlink頂部(z順序較高)(請參見注釋)。

<FlowDocumentScrollViewer>
    <FlowDocument>
        <Paragraph>
            The maximum speed is
            <Grid>
                <Button>No way!</Button>
                <ContentControl HorizontalAlignment="Center">
                    <Hyperlink>150</Hyperlink>
                </ContentControl>
            </Grid>
            in this road!
        </Paragraph>
    </FlowDocument>
</FlowDocumentScrollViewer>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM