我正在 WP 8.1 中开发一个音乐播放器应用程序,我正在尝试在其中实现跳转列表功能。为了实现跳转列表,我遵循此处给出的示例。
我正在对可用代码进行一些必要的更改,这就是我实现所需功能的方式,因为我对 C#、MVVM 和 WP 8.1 的了解很少。
但是我在我的 ViewModel 中遇到了错误
var items = ContactModel.CreateSampleData();
错误是:
Cannot assign void to an implicitly-typed local variable
可能的原因是什么????谁能帮我理解我哪里出错了。
using System.Collections;
using Windows.UI.Xaml.Data;
using JumpListSample.Common.JumpList;
using System.Collections.Generic;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using System;
using Windows.Storage;
using Windows.Storage.Search;
using System.Collections.ObjectModel;
namespace JumpListSample.ViewModels
{
public class ContactsViewModel
{
private IList data;
public IList Data
{
get
{
if (data == null)
{
var items = ContactModel.CreateSampleData();
data = items.ToAlphaGroups(x => x.Name);
}
return data;
}
}
private CollectionViewSource collection;
public CollectionViewSource Collection
{
get
{
if (collection == null)
{
collection = new CollectionViewSource();
collection.Source = Data;
collection.IsSourceGrouped = true;
}
return collection;
}
}
}
public class ContactModel
{
// constructor
public ContactModel()
{
Name = "name";
Albumart = new BitmapImage(new Uri("ms-appx:///Assets/Logo.scale-240.png"));
}
public async static void CreateSampleData()
{
ObservableCollection<ContactModel> data = new ObservableCollection<ContactModel>();
try
{
IReadOnlyList<IStorageItem> MusicLibrary = await KnownFolders.MusicLibrary.GetFoldersAsync(CommonFolderQuery.GroupByAlbum);
foreach (IStorageItem item in MusicLibrary)
{
ContactModel obj = new ContactModel();
IStorageItem musicItem = item;
obj.Name = musicItem.Name;
obj.Albumart = new BitmapImage(new Uri("ms-appx:///Assets/Logo.scale-240.png"));
data.Add(obj);
}
}
catch
{
}
finally
{
}
}
public string Name { get; set; }
public ImageSource Albumart { get; set; }
}
}
演示代码可以从这里下载。