WPF中FlowDocument中UIElement的绝对定位
Absolute positioning of UIElement in FlowDocument in WPF
我想要 Button
出现在 Hyperlink
之上。如您所见,它现在是 FlowDocument
的一部分,位于超链接旁边!但我希望它具有绝对位置,以便它可以出现在超链接上!我该怎么做?
<FlowDocumentScrollViewer>
<FlowDocument>
<Paragraph>
The maximum speed is
<Hyperlink>150</Hyperlink>
<InlineUIContainer>
<Button>No way!</Button>
</InlineUIContainer>
in this road!
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
您可以使用 StackPanel
到 "stack" 继承自 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>
我想要 Button
出现在 Hyperlink
之上。如您所见,它现在是 FlowDocument
的一部分,位于超链接旁边!但我希望它具有绝对位置,以便它可以出现在超链接上!我该怎么做?
<FlowDocumentScrollViewer>
<FlowDocument>
<Paragraph>
The maximum speed is
<Hyperlink>150</Hyperlink>
<InlineUIContainer>
<Button>No way!</Button>
</InlineUIContainer>
in this road!
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
您可以使用 StackPanel
到 "stack" 继承自 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>