我是一名学生,目前在窗口电话上做一个项目。基本上,我正在创建一个库应用程序。问题是,当我使用 listpicker 作为我要浏览的房间的选项时,每个选项都使用一个集成按钮。我希望每个按钮都能引导我进入不同的肖像页面。例如,当我按下选择“房间 101”的按钮时,它会将我带到“第 101 页”,如果选择“房间 102”,则打开“第 102 页”。这是我的 C# 代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
namespace Library
{
public partial class location : PhoneApplicationPage
{
public class SampleData
{
public string Floor
{
get;
set;
}
public string Room
{
get;
set;
}
}
public location()
{
InitializeComponent();
List<SampleData> dataSource = new List<SampleData>();
dataSource.Add(new SampleData() { Floor = "First",Room = "101" });
dataSource.Add(new SampleData() { Floor = "First",Room = "102" });
dataSource.Add(new SampleData() { Floor = "First", Room = "103" });
this.listPicker.ItemsSource = dataSource;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
SampleData data = (sender as Button).DataContext as SampleData;
ListPickerItem pressedItem =
this.listPicker.ItemContainerGenerator.ContainerFromItem(data) as ListPickerItem;
if (pressedItem != null )
{
this.NavigationService.Navigate(new Uri("/Room.xaml", UriKind.Relative));
}
}
}
}