wp7:在数据透视中导航动态数据透视项
我有一个数据透视表页面,其中有一个固定的数据透视项,并且根据数据,有动态数量的附加数据透视项。固定枢轴项目保留创建的新枢轴项目的超链接列表,其想法是单击任何链接并导航到该枢轴项目。
它看起来像这样:
FixedItem | DynamicItem1 | DynamicItem2
链接:DynamicItem1
链接:DynamicItem2
我面临的问题是超链接单击,它不会将我带到相应的枢轴项目,而是将我带到没有动态枢轴项目的枢轴页面。我使用以下代码进行导航:
hyperlink.NavigateUri = new Uri("/MainPage.xaml?name=" + p.name, UriKind.Relative);
其中 p.name 是枢轴项的名称。我不确定这是否是正确的语法,但令人困惑的是所有创建的枢轴项目都会丢失,只留下固定项目 - 就好像它正在打开枢轴页面的新实例一样。
然后,在 OnNavigedTo 中我尝试了以下操作:
if (NavigationContext.QueryString.ContainsKey("name"))
{
// URI is '/page?name=PivotItemToSelect'.
string selectedPivotItem = e.Uri.Query.Split('=').Last();
// Match PivotItemToSelect with the PivotItem's Name.
PivotItem pivotItemToShow = pivot.Items.Cast<PivotItem>().Single(i => i.Name == selectedPivotItem);
pivot.SelectedItem = pivotItemToShow;
base.OnNavigatedTo(e);
}
在第一行中,我收到一个异常,表明此操作无法在“相对”URI 上完成。我还能通过其他方式获得这些信息吗?
如果我将枢轴项名称更改为数字(例如 i),并将 i 作为索引传递,我将得到以下代码作为超链接按钮的 _click 方法 - 但在实际使用中,该名称很可能是文本字符串:
pivot.SelectedIndex = int.Parse(i);
我不确定我是否完全偏离了轨道,并且希望得到任何正确方向的指示。
谢谢。
I have a pivot page, with one fixed pivotitem, and depending on data, a dynamic number of additional pivotitems. The fixed pivotitem keeps a hyperlink list of the new pivotitems created, and the idea is to click any of the links and navigate to that pivotitem.
It would look something like this:
FixedItem | DynamicItem1 | DynamicItem2
link: DynamicItem1
link: DynamicItem2
The problem I am facing is with the hyperlink click, it doesn't take me to the respective pivotitem, but instead takes me to the pivot page with no dynamic pivotitems. I am using the following code for navigation:
hyperlink.NavigateUri = new Uri("/MainPage.xaml?name=" + p.name, UriKind.Relative);
where p.name is the name of the pivotitem. I am not sure if this is the right syntax, but what's confusing is that all the created pivotitems get lost, leaving only the fixeditem - as if it was opening a new instance of the pivot page.
Then, in the OnNavigatedTo I tried the following:
if (NavigationContext.QueryString.ContainsKey("name"))
{
// URI is '/page?name=PivotItemToSelect'.
string selectedPivotItem = e.Uri.Query.Split('=').Last();
// Match PivotItemToSelect with the PivotItem's Name.
PivotItem pivotItemToShow = pivot.Items.Cast<PivotItem>().Single(i => i.Name == selectedPivotItem);
pivot.SelectedItem = pivotItemToShow;
base.OnNavigatedTo(e);
}
On the first line, I get an exception that this operation cannot be done on a "relative" URI. Any other way I could that information?
If I change the pivotitem name to a number, say i, and pass that i as the index, I got the following code to work as the _click method of the hyperlinkbutton - but in real usage the name will most likely be a text string:
pivot.SelectedIndex = int.Parse(i);
I am not sure how totally off the track I am, and would appreciate any pointers in the right direction.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 OnNavigedTo 事件中访问 QueryString 的正确方法如下:
像这样使用 Pivot 控件进行导航似乎很奇怪,但由于我对应用程序的上下文一无所知,因此我假设您已选择它作为原因。
如果您正在设计一个具有要导航到的动态项目列表的应用程序,那么最好为链接列表设置一个页面,以及一个可以使用查询字符串绑定到您想要的特定对象的详细信息页面。这将表现得更好并且对您的用户更有意义。但同样,我不知道您的应用程序的上下文或您的推理,所以这取决于您! :)
The correct way to access the QueryString in your OnNavigatedTo event is like this:
Using a Pivot control for your navigation like this seems very strange, but since I know nothing about the context of your app, I'll assume you have chosen it for a reason.
If you are designing an app with a dynamic list of items to navigate to, it would be better to have a single page for your link list and a single detail page that can use the query string to bind to the specific object you are wanting. This will perform better and make more sense to your users. But again, I don't know the context of your app or your reasoning, so that's up to you! :)