首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用FileOpenPicker与Silverlight

使用FileOpenPicker与Silverlight
EN

Stack Overflow用户
提问于 2014-05-04 12:20:47
回答 1查看 1.3K关注 0票数 3

Windows 8.1支持文件打开和文件保存选择器。我想使用一个文件开放的选择与一个项目,从WP 8转换为WP8.1 (Silverlight)。

我可以按以下方式打开FileOpenPicker:

代码语言:javascript
复制
FileOpenPicker picker = new FileOpenPicker();
picker.FileTypeFilter.Add(".txt");
picker.PickSingleFileAndContinue(); 

现在,我发现的所有示例都使用了新的通用Windows运行时,其中的结果文件在App.xaml.cs中被捕获如下:

代码语言:javascript
复制
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)的另一个例子中得出了主要的想法:

代码语言:javascript
复制
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中使用以下方法:

代码语言:javascript
复制
private void Application_ContractActivated(object sender, IActivatedEventArgs e)
{
        var filePickerContinuationArgs = e as FileOpenPickerContinuationEventArgs;
        if (filePickerContinuationArgs != null)
        {
        // Handle file here
        }
}

但是这个方法从来没有在我的应用程序中调用过。

有人知道如何让FileOpenPicker与Silverlight WP8.1应用程序一起工作吗?

致以敬意,

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-04 13:08:31

似乎需要手动向Microsoft.Phone.Shell.PhoneApplicationService.Current.ContractActivated:添加一个事件处理程序。

代码语言:javascript
复制
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
        }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23456143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档