Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Samples/CameraCaptureUI/cpp-winui/cpp-winui/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "winrt/Microsoft.UI.Windowing.h"
#include "winrt/Windows.ApplicationModel.h"
#include "Winrt/Microsoft.UI.Xaml.Media.Imaging.h"
#include <winrt/Windows.Storage.Pickers.h>
#include <winrt/Microsoft.Windows.Storage.Pickers.h>
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Storage.Streams.h>
#include <winrt/Windows.Media.Playback.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ namespace winrt::DynamicRefreshRateTool::implementation

winrt::Windows::Foundation::IAsyncAction MainWindow::ChooseFolder_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e)
{
Windows::Storage::Pickers::FolderPicker picker;
picker.ViewMode(Windows::Storage::Pickers::PickerViewMode::List);
picker.SuggestedStartLocation(Windows::Storage::Pickers::PickerLocationId::ComputerFolder);
picker.as<IInitializeWithWindow>()->Initialize(GetActiveWindow());
Microsoft::Windows::Storage::Pickers::FolderPicker picker{ this->AppWindow().Id() };
picker.ViewMode(Microsoft::Windows::Storage::Pickers::PickerViewMode::List);
picker.SuggestedStartLocation(Microsoft::Windows::Storage::Pickers::PickerLocationId::ComputerFolder);


if (auto loggingFolder = co_await picker.PickSingleFolderAsync())
if (auto result = co_await picker.PickSingleFolderAsync())
{
m_loggingFolder = loggingFolder;
FolderPath().Text(m_loggingFolder.Path());
// Store the picked folder path directly as a string
auto folderPath = result.Path();
m_loggingFolderPath = std::wstring{ folderPath };
FolderPath().Text(folderPath);
FolderPath().Visibility(Visibility::Visible);
FolderNotSelected().Visibility(Visibility::Collapsed);
LoggingToggleSwitch().IsEnabled(true);
Expand All @@ -114,7 +114,7 @@ namespace winrt::DynamicRefreshRateTool::implementation

void MainWindow::StartLogging()
{
m_logger.emplace(std::wstring(m_loggingFolder.Path().c_str()));
m_logger.emplace(m_loggingFolderPath);
}

void MainWindow::StopLogging()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace winrt::DynamicRefreshRateTool::implementation
bool IsLogging();

std::optional<RefreshRateLogger> m_logger;
winrt::Windows::Storage::StorageFolder m_loggingFolder = nullptr;
std::wstring m_loggingFolderPath;

std::future<void> m_updateFuture;
bool running = true;
Expand Down
2 changes: 1 addition & 1 deletion Samples/Composition/DynamicRefreshRateTool/cpp-winui/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#include <wil/cppwinrt_helpers.h>

#include <Microsoft.UI.Xaml.Window.h>
#include <winrt/Windows.Storage.Pickers.h>
#include <winrt/Microsoft.Windows.Storage.Pickers.h>

#include <fstream>
#include <sstream>
Expand Down
13 changes: 9 additions & 4 deletions Samples/PhotoEditor/cpp-winui/PhotoEditor/DetailPage.xaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace winrt
using namespace Windows::Graphics::Effects;
using namespace Windows::Graphics::Imaging;
using namespace Windows::Storage;
using namespace Windows::Storage::Pickers;
using namespace Microsoft::Windows::Storage::Pickers;
using namespace Windows::Storage::Search;
using namespace Windows::Storage::Streams;
using namespace Windows::UI;
Expand Down Expand Up @@ -576,13 +576,18 @@ namespace winrt::PhotoEditor::implementation

IAsyncAction DetailPage::SaveButton_Click(IInspectable const&, RoutedEventArgs const&)
{
// Setup the picker.
auto picker = FileSavePicker{};
auto picker = FileSavePicker{ App::Window().AppWindow().Id() };
picker.SuggestedStartLocation(PickerLocationId::PicturesLibrary);
picker.SuggestedFileName(L"New Image");
picker.FileTypeChoices().Insert(L"Images", winrt::single_threaded_vector<hstring>({ L".jpg" }));

if (auto file = co_await picker.PickSaveFileAsync())
auto result = co_await picker.PickSaveFileAsync();
if (!result)
{
return;
}

if (auto file = co_await Windows::Storage::StorageFile::GetFileFromPathAsync(result.Path()))
{
if (auto stream = co_await file.OpenAsync(Windows::Storage::FileAccessMode::ReadWrite))
{
Expand Down
2 changes: 1 addition & 1 deletion Samples/PhotoEditor/cpp-winui/PhotoEditor/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <winrt/Windows.Graphics.Imaging.h>
#include <winrt/Windows.Storage.FileProperties.h>
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Storage.Pickers.h>
#include <winrt/Microsoft.Windows.Storage.Pickers.h>
#include <winrt/Windows.Storage.Search.h>
#include <winrt/Windows.Storage.Streams.h>
#include <wil/cppwinrt_helpers.h>
24 changes: 15 additions & 9 deletions Samples/PhotoEditor/cs-winui/DetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Microsoft.Windows.Storage.Pickers;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Media.Animation;
Expand Down Expand Up @@ -205,18 +207,22 @@ private async void ExportImage()
ds.DrawImage(img);
}


var fileSavePicker = new FileSavePicker()
var fileSavePicker = new FileSavePicker(App.WindowId)
{
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
SuggestedSaveFile = item.ImageFile
SuggestedFileName = item.ImageFile.DisplayName,
SuggestedFolder = await item.ImageFile.GetParentAsync().Path,
FileTypeChoices = {
{"JPEG files", new[] { ".jpg" }},
},
};

fileSavePicker.FileTypeChoices.Add("JPEG files", new List<string>() { ".jpg" });

WinRT.Interop.InitializeWithWindow.Initialize(fileSavePicker, App.WindowHandle);

var outputFile = await fileSavePicker.PickSaveFileAsync();
var result = await fileSavePicker.PickSaveFileAsync();
StorageFile outputFile;
if (result)
{
outputFile = await StorageFile.GetFileFromPathAsync(result.Path);
}

if (outputFile != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Windows.Storage;
using Windows.Storage.Pickers;
using Microsoft.Windows.Storage.Pickers;
using Microsoft.UI.Composition.Effects;
using Microsoft.UI.Xaml.Hosting;

Expand Down Expand Up @@ -228,19 +227,20 @@ private void UpdateEdgeModeProperties(StackPanel panel, ImageLayer layer)

private async void Button_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
WinRT.Interop.InitializeWithWindow.Initialize(openPicker, WinRT.Interop.WindowNative.GetWindowHandle(MainWindow.CurrentWindow));
StorageFile file = await openPicker.PickSingleFileAsync();

if (file != null)
var openPicker = new FileOpenPicker(MainWindow.CurrentWindow.AppWindow.Id)
{
Filename.Text = file.Name;
((ImageLayer)Layer).File = file;
ViewMode = PickerViewMode.Thumbnail,
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
FileTypeFilter = { ".jpg", ".jpeg", ".png" }
};

var result = await openPicker.PickSingleFileAsync();

if (result != null)
{
Filename.Text = System.IO.Path.GetFileName(result.Path);
((ImageLayer)Layer).FilePath = result.Path;
await ((ImageLayer)Layer).LoadResources();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.IO;
using SamplesCommon;
using Windows.Foundation;
using Windows.UI;
using Windows.Storage.Pickers;
using Microsoft.Windows.Storage.Pickers;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.Graphics.Effects;
Expand Down Expand Up @@ -221,20 +222,24 @@ private async void BackgroundCombo_SelectionChanged(object sender, SelectionChan
}
else
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
WinRT.Interop.InitializeWithWindow.Initialize(openPicker, WinRT.Interop.WindowNative.GetWindowHandle(MainWindow.CurrentWindow));
StorageFile file = await openPicker.PickSingleFileAsync();

if (file != null)
var openPicker = new FileOpenPicker(MainWindow.CurrentWindow.AppWindow.Id)
{
ViewMode = PickerViewMode.Thumbnail,
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
FileTypeFilter = { ".jpg", ".jpeg", ".png" },
};

var result = await openPicker.PickSingleFileAsync();
if (result != null)
{
BitmapImage bitmapImage = new BitmapImage();
IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);
bitmapImage.SetSource(stream);

// Use System.IO to create a file stream directly from the path
using (var fileStream = File.OpenRead(result.Path))
{
var randomAccessStream = fileStream.AsRandomAccessStream();
await bitmapImage.SetSourceAsync(randomAccessStream);
}

PreviewPanel.Background = new ImageBrush()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Storage;
using Windows.Storage.Pickers;
using Microsoft.Windows.Storage.Pickers;

namespace MaterialCreator
{
Expand Down Expand Up @@ -115,14 +115,19 @@ private async Task<StorageFile> LoadFromFilePath(string filePath)
await dialog.ShowAsync();

// Launch the picker
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".png");
WinRT.Interop.InitializeWithWindow.Initialize(openPicker, WinRT.Interop.WindowNative.GetWindowHandle(MainWindow.CurrentWindow));
return await openPicker.PickSingleFileAsync();
var openPicker = new FileOpenPicker(MainWindow.CurrentWindow.AppWindow.Id)
{
ViewMode = PickerViewMode.Thumbnail,
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
FileTypeFilter = { ".jpg", ".jpeg", ".png" },
};

var newResult = await openPicker.PickSingleFileAsync();
if (newResult != null && !string.IsNullOrEmpty(newResult.Path))
{
return await StorageFile.GetFileFromPathAsync(newResult.Path);
}
return null;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//*********************************************************

using Windows.Storage;
using Windows.Storage.Pickers;
using Microsoft.Windows.Storage.Pickers;
using Microsoft.UI.Composition;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Hosting;
Expand Down Expand Up @@ -246,14 +246,17 @@ private void OpenFile(object obj)
/// <returns>StorageFile that contains the selected video.</returns>
private async Task<StorageFile> OpenFile()
{
var picker = new FileOpenPicker();
picker.ViewMode = PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
// We could technically support more formats, all we would have to do is add them
// to the FileTypeFilter colleciton. For now we'll just use mp4 files.
picker.FileTypeFilter.Add(".mp4");

return await picker.PickSingleFileAsync();
var picker = new FileOpenPicker(default)
{
ViewMode = PickerViewMode.Thumbnail,
SuggestedStartLocation = PickerLocationId.VideosLibrary,
// We could technically support more formats, all we would have to do is add them
// to the FileTypeFilter colleciton. For now we'll just use mp4 files.
FileTypeFilter = { ".mp4" },
};

var result = await picker.PickSingleFileAsync();
return await StorageFile.CreateFromPathAsync(result.Path);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

using WindowsAISample.Models.Contracts;
using WindowsAISample.Util;
using Microsoft.Windows.Storage.Pickers;
using Microsoft.UI.Xaml.Media.Imaging;
using System;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.Graphics.Imaging;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using WinRT.Interop;

Expand Down Expand Up @@ -48,18 +48,20 @@ await DispatcherQueue.EnqueueAsync(async () =>

_pickInputImageCommand = new(async _ =>
{
var picker = new FileOpenPicker();
var window = App.Window;
var hwnd = WindowNative.GetWindowHandle(window);
InitializeWithWindow.Initialize(picker, hwnd);

picker.ViewMode = PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");

var file = await picker.PickSingleFileAsync();
var picker = new FileOpenPicker(App.window.Id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no compliable here, since i tried it.
Even you change to App.Window.AppWindow.Id will not be working in runtime, since i tried it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can put my version in your PR here.
Basically, beside using our picker, I also get rid of StorageFile in below usage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, @DinahK-2SO, I found that I cannot apply the file pickers here.
Since 1.8 stable build doesn't have all API need for previous 1.8 experiemental release for this AI project.
And our picker in 1.8 exp4 doesn't work here as well because of localization problem.

{
ViewMode = PickerViewMode.Thumbnail,
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
FileTypeFilter = { ".jpg", ".jpeg", ".png" },
};

var result = await picker.PickSingleFileAsync();
if (result == null)
{
return false;
}

var file = await StorageFile.CreateFromPathAsync(result.Path);
if (file != null)
{
using (IRandomAccessStream readStream = await file.OpenReadAsync())
Expand All @@ -79,18 +81,20 @@ await DispatcherQueue.EnqueueAsync(async () =>

_pickMaskImageCommand = new(async _ =>
{
var picker = new FileOpenPicker();
var window = App.Window;
var hwnd = WindowNative.GetWindowHandle(window);
InitializeWithWindow.Initialize(picker, hwnd);

picker.ViewMode = PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");

var file = await picker.PickSingleFileAsync();
var picker = new FileOpenPicker(App.Windows.Id)
{
ViewMode = PickerViewMode.Thumbnail,
SuggestedStartLocation = PickerLocationId.PicturesLibrary,
FileTypeFilter = { ".jpg", ".jpeg", ".png" },
};

var result = await picker.PickSingleFileAsync();
if (result == null)
{
return false;
}

var file = await StorageFile.CreateFromPathAsync(result.Path);
if (file != null)
{
using (IRandomAccessStream readStream = await file.OpenReadAsync())
Expand Down
Loading