Windows 8.1支持文件打开和文件保存选择器。我想使用一个文件开放的选择与一个项目,从WP 8转换为WP8.1 (Silverlight)。
我可以按以下方式打开FileOpenPicker:
FileOpenPicker picker = new FileOpenPicker();
picker.FileTypeFilter.Add(".txt");
picker.PickSingleFileAndContinue(); 现在,我发现的所有示例都使用了新的通用Windows运行时,其中的结果文件在App.xaml.cs中被捕获如下:
protected override void OnActivated(IActivatedEventArgs e) {
ContinuationActivatedEventArgs = e as IContinuationActivatedEventArgs;
if (ContinuationEventArgsChanged != null)
{
// Handle file here
}
} 问题是转换后的Silverlight应用程序没有实现这种方法。相反,我从Silverlight应用程序(http://msdn.microsoft.com/en-us/library/dn655125%28v=vs.105%29.aspx)的另一个例子中得出了主要的想法:
private void Application_Activated(object sender, ActivatedEventArgs e)
{
var eventArgs = e as IContinuationActivatedEventArgs;
if (eventArgs != null)
{
// Handle file here
}
}但这不起作用(例如,eventArgs总是NULL)。
这里还有另一个例子:http://msdn.microsoft.com/en-us/library/windowsphone/develop/dn642086%28v=vs.105%29.aspx。这将在app.xaml.cs中使用以下方法:
private void Application_ContractActivated(object sender, IActivatedEventArgs e)
{
var filePickerContinuationArgs = e as FileOpenPickerContinuationEventArgs;
if (filePickerContinuationArgs != null)
{
// Handle file here
}
}但是这个方法从来没有在我的应用程序中调用过。
有人知道如何让FileOpenPicker与Silverlight WP8.1应用程序一起工作吗?
致以敬意,
发布于 2014-05-04 13:08:31
似乎需要手动向Microsoft.Phone.Shell.PhoneApplicationService.Current.ContractActivated:添加一个事件处理程序。
Microsoft.Phone.Shell.PhoneApplicationService.Current.ContractActivated += Application_ContractActivated;
private void Application_ContractActivated(object sender, IActivatedEventArgs e)
{
var filePickerContinuationArgs = e as FileOpenPickerContinuationEventArgs;
if (filePickerContinuationArgs != null)
{
// Handle file here
}
}https://stackoverflow.com/questions/23456143
复制相似问题