Can't find out how to use File picker contracts for Windows Phone 8.1 Silverlight app. All documentations are related to Windows Store 8.1 Apps, but nothing is said related to Silverlight 8.1 Apps at https://msdn.microsoft.com/.
1 Answers
2
votes
It is done the same way as Share Target.
- Declare in your Package.appxmanifest File Open/Save Picker.
- In PhoneApplicationService.Launching event handler check whether args can be casted to PhoneFileOpen(Save)PickerLaunchingEventArgs:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
var fileOpenPickerArgs = (e as PhoneFileOpenPickerLaunchingEventArgs);
if (fileOpenPickerArgs != null)
{
this.FileOpenPickerUI = fileOpenPickerArgs.FileOpenPickerActivatedEventArgs.FileOpenPickerUI;
}
}
You can create own UriMapper that will navigate to FilePickerPage in case the app was launched with FilePickerArgs:
public class FilePickerUriMapper : UriMapperBase { public override Uri MapUri(Uri uri) { if ((Application.Current as App).FileOpenPickerUI != null) { return new Uri(uri.ToString().Replace("MainPage", "FilePickerPage"), UriKind.Relative); } return uri; } }
Set RootFrame UriMapper property to custom UriMapper in InitializePhoneApplication method:
RootFrame.UriMapper = new FilePickerUriMapper();
Also, you can handle navigation from Application Start page, in that case you won't need to implement UriMapper.
Create new page for FilePicker and handle user picking or adding files using FileOpen(Save)PickerUI, that you've taken from LaunchingEventArgs.
P.S You can't change the ApplicationBar when you're called with FilePickerContract.