我正在向 TextBlock 添加内联。 Run() 内联工作。当然,出于某种原因,Hyperlink() 在 Windows 8(使用 Windows.UI.Xaml.Documents)中已被弃用,因此我尝试使用 C# 将 HyperlinkButton 封装在 InlineUIContainer 中。我知道这个概念是合理的,但我的代码失败了。
如果我注释掉“using Windows.UI.Xaml.Documents;”这一行然后我让周围的两个内联显示在我的 ListView 中(使用下面的方法。)如果此行未注释,则“链接”的 Inlines.Add 将被抛出。我做错了什么?
public TextBlock enrichPostText(anFullPost post) { TextBlock text_block = new TextBlock(); text_block.Inlines.Clear();
var holdText = new Run();
holdText.Text = "Test start >> ";
text_block.Inlines.Add(holdText);
HyperlinkButton linkButton = new HyperlinkButton();
linkButton.NavigateUri = new Uri("http://www.cones.net");
linkButton.Content = "click me";
linkButton.Name = "_blank";
InlineUIContainer link = new InlineUIContainer();
link.Child = linkButton;
text_block.Inlines.Add(link);
var holdText2 = new Run();
holdText2.Text = " << end test.";
text_block.Inlines.Add(holdText2);
return (text_block);
}
最佳答案
刚在 MSDN 上找到这个可能会有帮助。显然 TextBlock 内容模型不支持 InlineUIContainers 所以它会抛出异常。 http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/96585db1-8ed4-4a12-8d63-b427dc0d543d/
关于c# - 尝试在 TextBlock 中内联 HyperLinkButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12967618/