Reputation: 11
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.";
}
}
}
}
Upvotes: 0
Views: 541
Reputation: 12019
For desktop apps, you need to use the IInitializeWithWindow
interface. Or you could just use the pickers built-in to WPF.
Upvotes: 0