pro*_*ock 8 microsoft-metro windows-8
如何在XAML中的Windows应用商店应用中创建格式正确的超链接?我尝试创建内联超链接,并希望使用staticresource设置样式:
<RichTextBlock Style="{StaticResource PageHeaderTextStyle}" Grid.ColumnSpan="2">
<Paragraph>
<Run>"A sentence with inline text "</Run>
<InlineUIContainer>
<HyperlinkButton Background="Yellow">
my link
</HyperlinkButton>
</InlineUIContainer>
<Run>... some more text</Run>
</Paragraph>
</RichTextBlock>
Run Code Online (Sandbox Code Playgroud)
我得到以下超链接与句子的其余部分不对齐:

好吧,我试过这个无济于事:
<RichTextBlock FontSize="20">
<Paragraph Foreground="White" FontFamily="Segoe UI Light">
<Run>Now is the time for</Run>
<InlineUIContainer>
<HyperlinkButton Content="all good men">
<HyperlinkButton.Template>
<ControlTemplate>
<TextBlock Margin="5,0,5,0" FontSize="20" FontFamily="Segoe UI Light"
Text="{Binding Content, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
</ControlTemplate>
</HyperlinkButton.Template>
</HyperlinkButton>
</InlineUIContainer>
<Run>to come to the aid of their country</Run>
</Paragraph>
</RichTextBlock>
Run Code Online (Sandbox Code Playgroud)
然后我尝试了这个:
<RichTextBlock FontSize="20">
<Paragraph Foreground="White" FontFamily="Segoe UI Light">
<Run>Now is the time for</Run>
<InlineUIContainer>
<TextBlock Margin="5,0,5,0" Tapped="TextBlock_Tapped_1">
<Underline><Run Text="all good men" /></Underline>
</TextBlock>
</InlineUIContainer>
<Run>to come to the aid of their country</Run>
</Paragraph>
</RichTextBlock>
Run Code Online (Sandbox Code Playgroud)
这就像一个魅力!

我不是假装实现你自己的超链接按钮不是一点点工作,而是这样想 - 你将100%控制它的布局!它很容易从它周围的字体样式继承!
合理?
对于未来的读者只是添加Windows 8.1简化此任务,Windows 8.1将Hyperlink元素添加到Windows.UI.Xaml.Documents命名空间中的XAML文本对象模型,所以现在我们可以简单地使用它:
<RichTextBlock>
<Paragraph FontSize="22">Please click on this <Hyperlink NavigateUri="http://www.link.com">link</Hyperlink>, thanks !</Paragraph>
</RichTextBlock>
Run Code Online (Sandbox Code Playgroud)
它看起来像这样:

| 归档时间: |
|
| 查看次数: |
5133 次 |
| 最近记录: |