在WPF中的FlowDocument中的UIElement的绝对定位
问题描述:
我想要一个Button
出现在Hyperlink
上。正如你可以看到它现在是FlowDocument
的一部分,并坐在超链接旁边!但我希望它具有绝对位置,以便它可以出现在超链接上!我怎样才能做到这一点?在WPF中的FlowDocument中的UIElement的绝对定位
<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>
谢谢,但我希望它是在hyperlink- – Vahid
你的意思是你希望它是“上面”所以你看不到的超级链接?如果是这样,为什么你需要超链接? – DinoM
我希望它在我超链接后出现!我已经使用Button来简化了!它将是Slider。超链接将是一个整数值,当我点击它时,滑块将出现!这是我的最终目标! – Vahid