-1

我不想为我的 uwp 应用程序创建照片上传方法,但没有办法这样做,因为我不能使用 FileOpenPicker 或任何其他选择器!它找不到 FileOpenPicker,即使声明为 Windows.Storage.Pickers.FileOpenPicker(); 它抱怨找不到类型或命名空间 Windows。即使我将using Windows.Storage.Pickers;NuGet UwpDesktop-Updated 安装在文件顶部也无济于事。这很奇怪,因为我已经在谷歌上搜索了好几天,但没有找到其他人遇到我的问题!

还有其他方法可以使用 c# .net core 在 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.";
            }
        }
    }
}

4

1 回答 1

0

对于桌面应用程序,您需要使用IInitializeWithWindow界面。或者您可以只使用 WPF 内置的选择器。

于 2021-01-26T08:41:51.553 回答