在以下http://www.geekchamp.com/articles/listpicker-for-wp7-in-depth我想設置我的ListPicker使用自定義類類型的列表填充,但出於某種原因,我沒有看到我的項目在視圖中綁定。我有什麼是如何創建ListPicker的ItemTemplate
MainPage.xaml中
<Grid.Resources>
<DataTemplate x:Name="SearchProviderItemTemplate">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Favicon}" />
<TextBlock Text="{Binding Name}" Margin="12,0,0,0"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Name="SearchProviderFullModeItemTemplate">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Favicon}" />
<TextBlock Text="{Binding Name}" Margin="12,0,0,0"/>
</StackPanel>
</DataTemplate>
</Grid.Resources>
...
<toolkit:ListPicker x:Name="SearchProviderListPicker"
Header="{Binding Path=LocalizedResources.SettingsPage_SearchProvider, Source={StaticResource LocalizedStrings}}" ItemTemplate="{Binding SearchProviderItemTemplate}"
FullModeHeader="{Binding Path=LocalizedResources.SettingsPage_SearchProvider, Source={StaticResource LocalizedStrings}}" FullModeItemTemplate="{Binding SearchProviderFullModeItemTemplate}"
SelectedIndex="{Binding}"
SelectionChanged="SearchProviderListPicker_SelectionChanged"
CacheMode="BitmapCache"/>
MainPage.xaml.cs中
List<ListItem> searchProviderList;
public MainPage()
{
InitializeComponent();
PopulateSearchProviderList();
}
private void PopulateSearchProviderList()
{
searchProviderList = new List<ListItem>();
searchProviderList.Add(new ListItem { Favicon = "", Name = "Bing", Address = "http://www.bing.com" });
searchProviderList.Add(new ListItem { Favicon = "", Name = "Google", Address = "http://www.google.com" });
SearchProviderListPicker.ItemsSource = searchProviderList;
}
出於某種原因,我都在ListPicker看到的是TestApp.Classes.ListItem
。我創建的類ListItem
只是以下
ListItem.cs
public string Favicon
{
get;
set;
}
public string Name
{
get;
set;
}
public string Address
{
get;
set;
}
的ItemTemplate =「{StaticRessource yourDataTemplate} – MatDev8