1. Create a button control in Xaml page.
MainPage.Xaml
<Button x:Name="btnPhotos" HorizontalAlignment="Left" Margin="2,256,0,0" VerticalAlignment="Top" FontFamily="Arial" Width="388" Height="96" Click="btnPhotos_Click">
<TextBlock x:Name="textBlock" Text="Photos" FontSize="28" Foreground="#FF7A7070" Width="210" Height="42"/>
</Button>
<Button x:Name="btnVideo" HorizontalAlignment="Left" Height="99" Margin="3,366,0,0" VerticalAlignment="Top" FontFamily="Arial" Width="387" Click="btnVideo_Click">
<TextBlock Name="textVideo" Text="Video" FontSize="28" Margin="10,0,23,0" Foreground="#FF7A7070" Width="210" Height="42"></TextBlock>
</Button>
2. Write the following code on code behind.
MainPage.Xaml.cs
========================
private async void btnPhotos_Click(object sender, RoutedEventArgs e)
{
photosProgressBar.Visibility = Visibility.Visible;
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
openPicker.PickMultipleFilesAndContinue();
}
private async void btnVideo_Click(object sender, RoutedEventArgs e)
{
videoProgressBar.Visibility = Visibility.Visible;
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
openPicker.FileTypeFilter.Add(".mp4");
//openPicker.FileTypeFilter.Add(".jpeg");
//openPicker.FileTypeFilter.Add(".png");
openPicker.PickMultipleFilesAndContinue();
}
public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
{
IReadOnlyList<StorageFile> files = args.Files;
if (files.Count > 0)
{
foreach (var item in files)
{
//Do your work
}
}
}
3. Write an event in App.Xaml.cs.
App.Xaml.cs
===========================
protected override void OnActivated(IActivatedEventArgs args)
{
// Sync osync = new Sync();
var root = Window.Current.Content as Frame;
var sync = root.Content as Sync;
if (sync != null && args is FileOpenPickerContinuationEventArgs)
{
sync.ContinueFileOpenPicker(args as FileOpenPickerContinuationEventArgs);
}
}
MainPage.Xaml
<Button x:Name="btnPhotos" HorizontalAlignment="Left" Margin="2,256,0,0" VerticalAlignment="Top" FontFamily="Arial" Width="388" Height="96" Click="btnPhotos_Click">
<TextBlock x:Name="textBlock" Text="Photos" FontSize="28" Foreground="#FF7A7070" Width="210" Height="42"/>
</Button>
<Button x:Name="btnVideo" HorizontalAlignment="Left" Height="99" Margin="3,366,0,0" VerticalAlignment="Top" FontFamily="Arial" Width="387" Click="btnVideo_Click">
<TextBlock Name="textVideo" Text="Video" FontSize="28" Margin="10,0,23,0" Foreground="#FF7A7070" Width="210" Height="42"></TextBlock>
</Button>
2. Write the following code on code behind.
MainPage.Xaml.cs
========================
private async void btnPhotos_Click(object sender, RoutedEventArgs e)
{
photosProgressBar.Visibility = Visibility.Visible;
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
openPicker.PickMultipleFilesAndContinue();
}
private async void btnVideo_Click(object sender, RoutedEventArgs e)
{
videoProgressBar.Visibility = Visibility.Visible;
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
openPicker.FileTypeFilter.Add(".mp4");
//openPicker.FileTypeFilter.Add(".jpeg");
//openPicker.FileTypeFilter.Add(".png");
openPicker.PickMultipleFilesAndContinue();
}
public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
{
IReadOnlyList<StorageFile> files = args.Files;
if (files.Count > 0)
{
foreach (var item in files)
{
//Do your work
}
}
}
3. Write an event in App.Xaml.cs.
App.Xaml.cs
===========================
protected override void OnActivated(IActivatedEventArgs args)
{
// Sync osync = new Sync();
var root = Window.Current.Content as Frame;
var sync = root.Content as Sync;
if (sync != null && args is FileOpenPickerContinuationEventArgs)
{
sync.ContinueFileOpenPicker(args as FileOpenPickerContinuationEventArgs);
}
}
No comments:
Post a Comment