在我的 WP7 应用程序中,我的 ListPicker 有这个 XAML:
<toolkit:ListPicker HorizontalAlignment="Left" ExpansionMode="FullScreenOnly" Height="70" x:Name="ddLinks" VerticalAlignment="Top" Width="419" FullModeHeader="Category" SelectionChanged="ddLinks_SelectionChanged">
<toolkit:ListPicker.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding linkCatName}" Name="lblLinkCat" />
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
<toolkit:ListPicker.FullModeItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding linkCatName}" Name="lblLinkCat" FontSize="48" />
</StackPanel>
</DataTemplate>
</toolkit:ListPicker.FullModeItemTemplate>
</toolkit:ListPicker>
后面的 C# 代码:
while (condition)
{
// code to set value of the vars
this.ddLinks.Items.Add(new LinkCats(linkCatName, linkCatAnchor, linksInCat));
}
还有几个对象:
public class LinkCats
{
public string linkCatName { get; set; }
public string linkCatAnchor { get; set; }
public List<Links> linksInCat { get; set; }
public LinkCats() { }
public LinkCats(string pLinkCatName, string pLinkCatAnchor, List<Links> pLinksInCat)
{
this.linkCatName = pLinkCatName;
this.linkCatAnchor = pLinkCatAnchor;
this.linksInCat = pLinksInCat;
}
}
public class Links
{
public string linkName { get; set; }
public string linkPath { get; set; }
public Links() { }
public Links(string pName, string pLink)
{
this.linkName = pName;
this.linkPath = pLink;
}
}
页面加载完成后,它会在控件中和调试时显示作为选定项添加的第一项。但是,如果我单击 ListPicker,则没有任何反应。我无法从其他选项中进行选择。