Когда я пытаюсь создать SecondaryTile
в PinToStartAsync
, я получаю ArgumentException
. Какие аргументы используются неправильно?
public const string LogoPath = "ms-appx:///Assets/monotone_no_bg.png";
public static async Task<bool> PinToStartAsync(Playlist playlist, bool isPlaylist)
{
string tilename = playlist.Name;
string tileid = isPlaylist ? tilename : $"{tilename}+++{playlist.Artist}";
string path = LogoPath;
if (playlist.DisplayItem.Source != null && await SecondaryTileFolder.TryGetItemAsync(tilename) == null)
{
StorageFile thumbnail = await (await GetStorageItemThumbnailAsync(playlist.DisplayItem.Source.Path)).SaveAsync(SecondaryTileFolder, tilename);
path = thumbnail.Path;
}
var tile = new SecondaryTile(tileid, tilename, isPlaylist.ToString(), new Uri(path), TileSize.Default);
// Other code
}
// This function saves a StorageItemThumbnail and returns a StorageFile
public static async Task<StorageFile> SaveAsync(this StorageItemThumbnail thumbnail, StorageFolder folder, string name)
{
using (var stream = thumbnail.CloneStream())
{
var decoder = await BitmapDecoder.CreateAsync(stream);
var softwareBitmap = await decoder.GetSoftwareBitmapAsync();
var filename = $"{name}.png";
var item = await folder.TryGetItemAsync(filename);
var file = await folder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);
if (item == null)
{
using (var filestream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, filestream);
encoder.SetSoftwareBitmap(softwareBitmap);
await encoder.FlushAsync();
}
}
return file;
}
}
Больше исходного кода здесь внизу.