简体   繁体   English

具有Tag属性的Xaml超链接元素

[英]Xaml hyperlink element with Tag property

I'm currently adding <hyperlink /> 's inside a TextBlock element in my Windows Store Runtime app (Xaml, C#), However these hyperlinks are navigating internally so the NavigateUri is useless to me. 我目前正在Windows Store Runtime应用程序(Xaml,C#)的TextBlock元素内添加<hyperlink /> ,但是这些超链接在内部进行导航,因此NavigateUri对我来说毫无用处。

I can add a Click event handler which navigates to the correct page when the hyperlink is clicked, but I also need to pass a parameter (string) to the new page unique to the hyperlink. 我可以添加一个Click事件处理程序,当单击超链接时,该事件处理程序可导航到正确的页面,但是我还需要将参数(字符串)传递给该超链接唯一的新页面。

This would be perfect if it had a Tag Element as I could store the parameter inside the Tag property and pass that in on navigation. 如果它具有Tag元素,那将是完美的,因为我可以将参数存储在Tag属性中,并将其传递给导航。 However hyperlink class has no such property. 但是,超链接类没有这样的属性。

What element could I use in its place? 我可以用什么元素代替它? bearing in mind this goes inline with the rest of the text. 请记住,这与本文的其余部分保持一致。 Or is there away to pass this information to the Click handler without using the Tag property? 还是可以不使用Tag属性将信息传递给Click处理程序?

You can try to subclass Hyperlink and add the required property as well as internally handle the click event in the newly derived class. 您可以尝试对Hyperlink进行子类化,并添加必需的属性,并在内部处理新派生类中的click事件。

If you'd rather avoid that - you can implement and attached property (just like Grid.Row ) that has the link information. 如果您希望避免这种情况-您可以实现并附加具有链接信息的属性 (就像Grid.Row一样)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM