1
一個類似的問題被問到here,但我也想知道是否有一種方法來限制這個filePicker到4個圖像,還是我必須實現這個我自己?c#filepicker限制到4選擇Windows Phone 8.1
謝謝你
一個類似的問題被問到here,但我也想知道是否有一種方法來限制這個filePicker到4個圖像,還是我必須實現這個我自己?c#filepicker限制到4選擇Windows Phone 8.1
謝謝你
這不是很漂亮,但它現在的作品。 我聲明瞭名爲myimageList和alt-myImageList的ObservableCollection
類型的兩個全局變量。我只是檢查這些集合的大小,並從這一點開始。
這是代碼:
private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1)
{
FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;
if (args != null)
{
if (args.Files.Count == 0) return;
view.Activated -= viewActivated;
foreach (var item in args.Files)
{
// instead of item args.Files[0];
StorageFile storageFile = item;
var stream = await storageFile.OpenAsync(FileAccessMode.Read);
var bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(stream);
var wbImage = new WriteableBitmap(bitmapImage.PixelWidth, bitmapImage.PixelHeight);
wbImage.SetSource(stream);
//var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
//bitmapImage.UriSource = new Uri(item.Path, UriKind.Absolute);
if (myImageList.Count < 4)
{
myImageList.Add(bitmapImage);
alt_myImageList.Add(item);
ErrorMessage.Text = "";
}
else
{
ErrorMessage.Text = "Please pick not more than 4 pictures";
}
}
}