本文介绍了Silverlight使用HyperlinkBut​​ton在页面之间传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示用户列表的页面。每个用户都有一个ID和一个HyperlinkBut​​ton来观看有关用户的更多细节。

I have a page that displays a list of users. each user has an ID and a HyperlinkButton to watch more details about the user.

当按下HyperlinkBut​​ton时,我想导航到另一个页面(称为UserDetails)并以某种方式读取被按下的用户的ID。

When pressing the HyperlinkButton, I would like to navigate to another page (called UserDetails) and somehow read the ID of the user that was pressed.

我该怎么做?

谢谢,
Ronny

Thanks, Ronny

推荐答案

我找到了一个很好的解决方案,但我希望听到一些更优雅的东西。

I Found a nice solution, but I would like to hear something that is more elegant.

在UriMapper部分,我添加了另一个UriMapping:

Within the UriMapper section I have added another UriMapping:

<uriMapper:UriMapping Uri="/UserDetails/{UserId}" MappedUri=/Views/UserDetails.xaml"/>

通过这样做,所有导航格式为/ UserDetails / XXX将导航到同一页面,UserDetails.xaml。

By doing so, all navigation in the format of "/UserDetails/XXX will be navigated to same page, UserDetails.xaml.

所以现在我的HyperlinkBut​​ton生成了一个使用所需格式的NavigateUri:

So now my HyperlinkButton is generated with a NavigateUri with the needed format:

NavigateUri =/ UserDetails / 1234

NavigateUri="/UserDetails/1234"

现在,在UserDetails上。 X aml page,在OnNavigatedTo方法中,我可以解析Uri参数(e.Uri)并相应地加载用户详细信息。

Now, on the UserDetails.xaml page, in the OnNavigatedTo method, I can parse the Uri parameter (e.Uri) and load the User details accordingly.

这篇关于Silverlight使用HyperlinkBut​​ton在页面之间传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 01:12