我正在尝试让我的longlistselector导航到不同的页面,根据所选的选项。例如,A导航到a.xaml B导航到b.xaml,与C D E等相同。
的Xaml
<phone:LongListSelector
SelectionChanged="SelectionChanged"
x:Name="AddrBook"
JumpListStyle="{StaticResource AddrBookJumpListStyle}"
Background="Transparent"
GroupHeaderTemplate="{StaticResource AddrBookGroupHeaderTemplate}"
ItemTemplate="{StaticResource AddrBookItemTemplate}"
LayoutMode="List"
IsGroupingEnabled="true"
HideEmptyGroups ="true" Foreground="Black" Margin="0,20,0,0" FontSize="32"/>
代码背后:
{
public partial class ASectionPopSpanish : PhoneApplicationPage
{
public ASectionPopSpanish()
{
InitializeComponent();
List<AddressBook> source = new List<AddressBook>();
source.Add(new AddressBook("Joe", "Davidbisbal"));
source.Add(new AddressBook("AdJoe", "Davidbisbal"));
source.Add(new AddressBook("BJoe", "Davidbisbal"));
source.Add(new AddressBook("VJoe", "Davidbisbal"));
source.Add(new AddressBook("VJoe", "Davidbisbal"));
source.Add(new AddressBook("CJoe", "Davidbisbal"));
source.Add(new AddressBook("EJoe", "Davidbisbal"));
source.Add(new AddressBook("Joe", "Davidbisbal"));
List<AlphaKeyGroup<AddressBook>> DataSource = AlphaKeyGroup<AddressBook>.CreateGroups(source,
System.Threading.Thread.CurrentThread.CurrentUICulture,
(AddressBook s) => { return s.LastName; }, true);
AddrBook.ItemsSource = DataSource;
}
public class AddressBook
{
public string LastName
{
get;
set;
}
public string SectionPage
{
get;
set;
}
public AddressBook(string lastname, string sectionpage)
{
this.LastName = lastname;
this.SectionPage = sectionpage;
}
}
private void SelectionChanged(object sender, SelectionChangedEventArgs e)
{
AddressBook selectedAddress = (AddressBook)AddrBook.SelectedItem;
if (AddrBook.SelectedItem == null)
return;
NavigationService.Navigate(new Uri(AddressBook.SelectedItem.SectionPage & ".xaml", UriKind.Relative));
AddrBook.SelectedItem = null;
}
}
}
我知道我需要实施一个选择改变,但无法弄清楚该怎么做,有人可以帮我一把吗?
答案 0 :(得分:0)
您的代码段中似乎缺少的是,将selector_SelectionChanged
方法附加到SelectionChanged
LongListSelector
事件的XAML /代码:
<phone:LongListSelector
SelectionChanged="selector_SelectionChanged"
x:Name="AddrBook"
.....
...../>
此外,我们需要将LLS的SelectedItem转换为特定类型,以便能够访问其完整的属性集:
AddressBook selectedAddress = (AddressBook)AddrBook.SelectedItem;
NavigationService.Navigate(new Uri(selectedAddress.SectionPage + ".xaml", UriKind.Relative));