WP7 - 当列表框位于项目模板内时访问列表框中的选定项目
我有一个包含列表框的数据透视项模板
<controls:Pivot x:Name="MainPivot" ItemsSource="{Binding PivotItemHeaders}" Title="CLASS TIMETABLE" >
<controls:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Description}"/>
</DataTemplate>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.ItemTemplate>
<DataTemplate>
<ListBox x:Name="Events" ItemsSource="{Binding allEventItems}" ItemTemplate="{StaticResource EventDisplay2}"/>
</DataTemplate>
</controls:Pivot.ItemTemplate>
</controls:Pivot>
在后面的代码中我想访问该列表框的 selectedItem 但我无法“获取”列表框,因为 ity (大概)在模板内
,即
this.NavigationService.Navigate(new Uri("/View/EventEdit.xaml?selectedEvent=" + Events.SelectedItem, UriKind.Relative));
事件列表框没有被认可。
假设我可以传递 get 对象并将其作为参数传递,我可以使用什么代码来检索它
我知道它以 受保护的重写 void OnNavigateTo(NavigationEventArgs e) { if (NavigationContext.QueryString.ContainsKey("SelectedEvent")) {
但我不确定从参数中提取对象的语法/代码
欣赏如何从此列表框中获取 selectedItem 以及获取传递对象的代码
- 谢谢
I have a Pivot item template that includes a listbox
<controls:Pivot x:Name="MainPivot" ItemsSource="{Binding PivotItemHeaders}" Title="CLASS TIMETABLE" >
<controls:Pivot.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Description}"/>
</DataTemplate>
</controls:Pivot.HeaderTemplate>
<controls:Pivot.ItemTemplate>
<DataTemplate>
<ListBox x:Name="Events" ItemsSource="{Binding allEventItems}" ItemTemplate="{StaticResource EventDisplay2}"/>
</DataTemplate>
</controls:Pivot.ItemTemplate>
</controls:Pivot>
In the code behind I want to access the selectedItem of that listbox but I cannot 'get' to the listbox as such because ity is (presumably) within the template
i.e
this.NavigationService.Navigate(new Uri("/View/EventEdit.xaml?selectedEvent=" + Events.SelectedItem, UriKind.Relative));
The Events listbox is not being recognised.
Assuminh I can pass get the object and pass it through as a parameter, what code can I use to retrieve it
I know its starts with
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (NavigationContext.QueryString.ContainsKey("SelectedEvent"))
{
But I am unsure of the syntax/code to extract out the object from the parameters
Appreciate how I can get the selectedItem from this listbox and the code to get the object being passed through
- thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
SelectionChanged
事件在值更改时被告知:然后在后面的代码中:
您可以使用以下方式访问该值
NavigationContext.QueryString["selectedEvent"]
,但您只能将字符串存储在导航查询字符串中。如果您的列表框当前绑定到对象,您需要选择一个键,然后使用该键从第二页查找该事件。Rather than attempt to access the ListBox, you could use the
SelectionChanged
event to be told when the value changes:And then in your code behind:
You can access the value using
NavigationContext.QueryString["selectedEvent"]
, but you can only store strings in navigation query strings. If your listbox is currently bound to objects, you'll need to select a key and then find that event from the second page using that key.