Reputation: 4452
Windows Phone 8.1 supports file open and file save pickers. I want to use a file open picker with a project which was converted form WP 8 to WP 8.1 (Silverlight).
I can open the FileOpenPicker as follows:
FileOpenPicker picker = new FileOpenPicker();
picker.FileTypeFilter.Add(".txt");
picker.PickSingleFileAndContinue();
Now, all examples I have found use the new universal Windows runtime where the resulting files are catched as follows in the App.xaml.cs:
protected override void OnActivated(IActivatedEventArgs e) {
ContinuationActivatedEventArgs = e as IContinuationActivatedEventArgs;
if (ContinuationEventArgsChanged != null)
{
// Handle file here
}
}
The problem is that the converted Silverlight apps do not implement this method. Instead I derived the principle idea from another example for Silverlight apps (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
}
}
But this does not work (e.g. eventArgs
is always NULL
).
There is another example here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/dn642086%28v=vs.105%29.aspx. This uses the following method in the app.xaml.cs:
private void Application_ContractActivated(object sender, IActivatedEventArgs e)
{
var filePickerContinuationArgs = e as FileOpenPickerContinuationEventArgs;
if (filePickerContinuationArgs != null)
{
// Handle file here
}
}
But this method is never called in my app.
Has someone a hint/idea how get the FileOpenPicker to work with a Silverlight WP8.1 app?
Regards,
Upvotes: 3
Views: 1276
Reputation: 1402
It seems that one needs to manually add an event handler to 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
}
}
Upvotes: 2