0

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, even if declared like Windows.Storage.Pickers.FileOpenPicker(); It complains about the type or namespace Windows not being found. Even when I put using Windows.Storage.Pickers; at the top of the file I have installed NuGet UwpDesktop-Updated to no avail. 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?

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.";
            }
        }
    }
}

5
  • Could you please describe in detail how you created the project? Is the creation process the same as in this document? In addition, you could check whether your Windows 10 SDK is installed correctly with Visual Studio Installer. Commented Jan 25, 2021 at 9:01
  • thanks for the reply! I created a windows template studio (universal studio), then chose mvvm basic instead of codebehind Commented Jan 26, 2021 at 12:56
  • Is your question solved? Do you have any other concerns? Commented Jan 27, 2021 at 2:06
  • nope, I just gave up. nothing i could find except come to the realisation that uwp is useless and definitely not for the future Commented Jan 30, 2021 at 14:55
  • Logically, there is nothing wrong with your code. Could you please provide us a minimal reproducible example by OneDrive or GitHub for testing? Commented Feb 1, 2021 at 8:07

1 Answer 1

0

For desktop apps, you need to use the IInitializeWithWindow interface. Or you could just use the pickers built-in to WPF.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you for taking the time to reply and helping a java refugee in the weird world of windows programming

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.