[英]can't use FileOpenPicker in uwp c# .net core, any alternative ways to upload pictures in uwp?
I wan't to create a photo uploading method for my uwp app but there is no way to do it because I can't use FileOpenPicker or any of the other pickers, It cannot find FileOpenPicker.我不想为我的 uwp 应用程序创建照片上传方法,但没有办法这样做,因为我不能使用 FileOpenPicker 或任何其他选择器,它找不到 FileOpenPicker。 even if declared like Windows.Storage.Pickers;FileOpenPicker().
即使声明为 Windows.Storage.Pickers;FileOpenPicker()。 It complains about the type or namespace Windows not being found.
它抱怨找不到类型或命名空间 Windows。 Even when I put
using Windows.Storage.Pickers;
即使我
using Windows.Storage.Pickers;
at the top of the file I have installed NuGet UwpDesktop-Updated to no avail.在文件的顶部我已经安装了 NuGet UwpDesktop-Updated 无济于事。 This is strange because I have been googling for days without finding anyone else with my issue!
这很奇怪,因为我已经在谷歌上搜索了好几天,但没有找到其他人遇到我的问题!
Are there any other ways to upload a photo in uwp with c# .net core?还有其他方法可以使用 c# .net 核心在 uwp 中上传照片吗?
using System;
using System.Windows.Controls;
using Image.ViewModels;
namespace Image.Views
{
public partial class MainPage : Page
{
public MainPage(MainViewModel viewModel)
{
InitializeComponent();
DataContext = viewModel;
}
private async void Clicked(object sender, EventArgs e)
{
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");
Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
// Application now has read/write access to the picked file
this.textBlock.Text = "Picked photo: " + file.Name;
}
else
{
this.textBlock.Text = "Operation cancelled.";
}
}
}
}
For desktop apps, you need to use the IInitializeWithWindow
interface .对于桌面应用程序,您需要使用
IInitializeWithWindow
接口。 Or you could just use the pickers built-in to WPF.或者您可以只使用 WPF 内置的选择器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.