c#文件选择器限制为4个Windows Phone 8.1
有人问了一个类似的问题,但我也想知道是否有办法将此文件选择器限制为4个图像,或者我必须自己实现这一点c#文件选择器限制为4个Windows Phone 8.1,c#,windows-phone-8.1,winrt-xaml,C#,Windows Phone 8.1,Winrt Xaml,有人问了一个类似的问题,但我也想知道是否有办法将此文件选择器限制为4个图像,或者我必须自己实现这一点 谢谢你它不漂亮,但现在可以用了。 我声明了两个名为myimageList和alt myimageList的ObservableCollection类型的全局变量。我刚刚检查了这些集合的大小,并从这一点开始着手 这就是代码: private async void viewActivated(CoreApplicationView sender, IActivatedEventArg
谢谢你它不漂亮,但现在可以用了。 我声明了两个名为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";
}
}
}
private async void view已激活(CoreApplicationView发送方,IActivatedEventArgs args1)
{
FileOpenPickerContinuationEventArgs args=args1作为FileOpenPickerContinuationEventArgs;
如果(args!=null)
{
如果(args.Files.Count==0)返回;
view.Activated-=视图已激活;
foreach(args.Files中的变量项)
{
//而不是项args.Files[0];
StorageFile StorageFile=项目;
var stream=await-storageFile.OpenAsync(FileAccessMode.Read);
var bitmapImage=新的bitmapImage();
等待bitmapImage.SetSourceAsync(流);
var wbImage=new WriteableBitmap(bitmapImage.PixelWidth,bitmapImage.PixelHeight);
wbImage.SetSource(流);
//var decoder=wait Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(流);
//bitmapImage.UriSource=新Uri(item.Path,UriKind.Absolute);
如果(myImageList.Count<4)
{
添加(位图图像);
alt_myImageList.Add(项目);
ErrorMessage.Text=“”;
}
其他的
{
ErrorMessage.Text=“请选择不超过4张图片”;
}
}
}
它不漂亮,但现在可以用了。
我声明了两个名为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";
}
}
}
private async void view已激活(CoreApplicationView发送方,IActivatedEventArgs args1)
{
FileOpenPickerContinuationEventArgs args=args1作为FileOpenPickerContinuationEventArgs;
如果(args!=null)
{
如果(args.Files.Count==0)返回;
view.Activated-=视图已激活;
foreach(args.Files中的变量项)
{
//而不是项args.Files[0];
StorageFile StorageFile=项目;
var stream=await-storageFile.OpenAsync(FileAccessMode.Read);
var bitmapImage=新的bitmapImage();
等待bitmapImage.SetSourceAsync(流);
var wbImage=new WriteableBitmap(bitmapImage.PixelWidth,bitmapImage.PixelHeight);
wbImage.SetSource(流);
//var decoder=wait Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(流);
//bitmapImage.UriSource=新Uri(item.Path,UriKind.Absolute);
如果(myImageList.Count<4)
{
添加(位图图像);
alt_myImageList.Add(项目);
ErrorMessage.Text=“”;
}
其他的
{
ErrorMessage.Text=“请选择不超过4张图片”;
}
}
}