如何将选定的文件详细信息传递到另一个页面 - UWP? [英] How to pass seleced file details to another page - UWP?
本文介绍了如何将选定的文件详细信息传递到另一个页面 - UWP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个启动页面(MainPage1.xaml).有一个按钮可以从设备中选择视频文件.现在我想在下一页 (MainPage2.xaml) 上播放选定的文件.我怎样才能在下一页得到这个选定的文件 StorageFile file
?
I have a launcher page(MainPage1.xaml).There is a button to select video file from device. Now I want to play that selected file on next page (MainPage2.xaml). How can I get this selcted file StorageFile file
on next page?
private async void Button_Click(object sender, RoutedEventArgs e)
{
StorageFile file;
FileOpenPicker openPicker = new FileOpenPicker();
foreach (string extension in FileExtensions.Video)
{
openPicker.FileTypeFilter.Add(extension);
}
file = await openPicker.PickSingleFileAsync();
this.Frame.Navigate(typeof(MainPage2), file);
}
推荐答案
您必须覆盖页面(下一页)中的 OnNavigatedTo()
方法,该方法需要 StorageFile代码>:
You have to override the OnNavigatedTo()
method in your page (next Page) which is expecting the StorageFile
:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.Parameter != null)
{
StorageFile file = (StorageFile)e.Parameter;
}
}
希望这有帮助..
这篇关于如何将选定的文件详细信息传递到另一个页面 - UWP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文