以编程方式制作文本块,文本之间带有超链接
在 XAML 中,我有以下代码:
<Label Width="120" Height="20" Name="label1" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Bottom">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left">
click
<Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="foo">here</Hyperlink>
please
</TextBlock>
</Label>
现在我想删除整个 TextBlock XAML 并以编程方式添加该位。我可以轻松创建 TextBlock、将 Text 属性设置为“请单击”并将超链接添加到 TextBlock.Content
。但是如何将超链接放置在“点击”和“请”之间呢?如何将超链接的文本设置为“此处”?
我没有太多进展,到目前为止我所得到的就是:
label2.Content = new TextBlock() { Text = "click please" };
//(label2.Content as TextBlock).Content does not exist?
//and even if it does.. how do I squeeze the hyperlink in between the text?
In XAML I have the following code:
<Label Width="120" Height="20" Name="label1" SnapsToDevicePixels="True" HorizontalAlignment="Left" VerticalAlignment="Bottom">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left">
click
<Hyperlink RequestNavigate="Hyperlink_RequestNavigate" NavigateUri="foo">here</Hyperlink>
please
</TextBlock>
</Label>
Now I'd like to get rid of the whole TextBlock XAML and add that bit programmatically. I have no trouble creating the TextBlock, setting the Text property to 'click please' and adding a Hyperlink to TextBlock.Content
. But how do I position the Hyperlink in between 'click' and 'please'? And how do I set the text of the hyperlink to 'here'?
I haven't got much going, so far all I got is this:
label2.Content = new TextBlock() { Text = "click please" };
//(label2.Content as TextBlock).Content does not exist?
//and even if it does.. how do I squeeze the hyperlink in between the text?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是添加中间带有可点击链接的
TextBlock
的代码:Here's the code to add a
TextBlock
with a clickable link in the middle :