可能有人帮我编码我自己的通用Windows商店应用程序我希望我的xaml页面选择一个文件,然后使用Windows Phone 8.1上的共享合同共享它。问题是我的Windows Phone 8.1应用程序,当我选择一个文件时,它遇到一个断点并且无法识别这行代码IReadOnlyList pickedFiles = await filePicker.PickMultipleFilesAsync()。这适用于Windows 8.1版本而不是Windows Phone 8.1版本。
private async void SelectFilesButton_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker filePicker = new FileOpenPicker
{
ViewMode = PickerViewMode.List,
SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
FileTypeFilter = { "*" }
};
IReadOnlyList<StorageFile> pickedFiles = await filePicker.PickMultipleFilesAsync();
if (pickedFiles.Count > 0)
{
this.storageItems = pickedFiles;
// Display the file names in the UI.
string selectedFiles = String.Empty;
for (int index = 0; index < pickedFiles.Count; index++)
{
selectedFiles += pickedFiles[index].Name;
if (index != (pickedFiles.Count - 1))
{
selectedFiles += ", ";
}
}
NotifyUser(String.Format("Picked files: ") + selectedFiles + ".", NotifyType.StatusMessage);
ShareStep.Visibility = Visibility.Visible;
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager,
DataRequestedEventArgs>(this.ShareStorageItemsHandler);
// If the user clicks the share button, invoke the share flow programatically.
DataTransferManager.ShowShareUI();
}
private async void ShareStorageItemsHandler(DataTransferManager sender,DataRequestedEventArgs e)
{
DataRequest request = e.Request;
request.Data.Properties.Title = TitleInputBox.Text;
request.Data.Properties.Description = DescriptionInputBox.Text;
// Because we are making async calls in the DataRequested event handler,
// we need to get the deferral first.
DataRequestDeferral deferral = request.GetDeferral();
// Make sure we always call Complete on the deferral.
try
{
request.Data.SetStorageItems(this.storageItems);
}
finally
{
deferral.Complete();
}
}
答案 0 :(得分:0)
Windows Phone 8.1上的文件选择器API的工作方式略有不同。您需要调用FileOpenPicker.PickMultipleFilesAndContinue而不是FileOpenPicker.PickMultipleFilesAsync。本文提供了更多上下文:https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631755.aspx。这在我的构建演讲中也有介绍:http://channel9.msdn.com/Events/Build/2014/2-520。
最后,答案是:Windows Phone, pick file using PickSingleFileAndContinue or PickMultipleFilesAndContinue StackOverflow问题也有一个样本。
答案 1 :(得分:0)
在Win10 SDK的预览中,它与WinRT上的工作方式相同,因此Phone和&其他任何东西都只会使用PickMultipleFilesAsync